Friday 10 August 2012

PostGIS and NAD27 coordinate transformations gotcha

I have not yet seen any PostGIS documentation explaining details of NAD27 transformation.
This is a hughe PostGIS pitfall so keep reading!

PostGIS relies on Proj4 library to perform coordinate transformations.
Accurate data transformation to and from North American Datum 1927 (NAD27) requires an appropriate datum grid shift file. Datum grid shift files usually are not part of standard proj4 library, on Linux freely distributable grid files are usually part of package proj-data or proj-nad depending on platform.
The problem is that PostGIS does not use files from the common proj4 data folder (on Ubuntu  /usr/share/proj).
A copy of all shift files must be placed in $POSTGRES_HOME/contrib/postgis/proj folder.
You can also find download links to additional grid shift files for various countries on proj4 website: http://trac.osgeo.org/proj/

This is a hughe pitfall because PostGIS will give no warning about missing grid files, function ST_Transform() will silently fall back to using much simpler calculations and therefore introduce transformation inaccuracies. If you are working with surveying data then this is crucial!

As soon as grid files are placed in proj folder PostGIS will quietly start taking advantage of them. Some tweaking might be required if you are working with other country datums. Here is some basic explanation of how Proj4 nadgrids work:
http://trac.osgeo.org/proj/wiki/GenParms#nadgrids-GridBasedDatumAdjustments


Ubuntu Quirks

Default Keyboard Layout

I had installed Latvian keyboard and my Ubuntu/Kubuntu and could not revert to English (UK) no matter what I did. Terminals like Alt-F2 would still be running Latvian locale. This command helped me to wipe out original settings and reinstall keyboard layout:
sudo dpkg-reconfigure keyboard-configuration

Overlay Scrollbars

I hate overlay scrollbars which were introduced in Ubuntu 11.04. Gmail has them. They are just silly. They are invisible when inactive and if you have a long document it's very difficult to hit the scrollbar right. So much pissing around just to scroll something! This command helped me to roll back to classic scrollbar:

sudo echo "export LIBOVERLAY_SCROLLBAR=0">/etc/X11/Xsession.d/80overlayscrollbars

Wednesday 8 August 2012

Skincare for climbers

My friend recently asked me a question:
"What is you suggestion for skin pain in climbing? Every time I climb, my finger skin get scaly and brittle so that it starts to become unbearable to keep a hold for longer than a couple of seconds. I always have to stop climbing because of this shit and not because I'm pumped or tired."

Here is what you can do...

Making your finger skin tough

You will have to gradually grow and toughen your finger skin by climbing regularly for 2 to 4 weeks. This requires 2-4 sessions per week. 
During this time you should spend most of the time on easy-ish problems. This is about getting some mileage under your belt. Therefore climbing routes would be the best but short and frequent boulder sessions will do too.
At the end of this period you will acquire essential calluses and your fingertips will desensitize and therefore will be more resistant to pain.

During the session

If you want your skin to last and become tougher then do plenty of easy (for you) problems with varied holds.
Certainly warm up, get your fingers warm before doing hard stuff. Warm fingers are essential for feeling the holds better and applying just the right amount of force.
If your fingertips are sore then try climbing problems with slopers or pinches, simply avoid fingery and sharp stuff. Choose different style problem that does not hurt and work on mileage, endurance or something else.
Try to take holds as static and accurate as you can, be smooth and fluid. Let your body and muscle do the work, not the fingers! Don't slap for holds and avoid sliding off. Try not to overgrip or overcrimp holds!

When pain has arrived and is almost unbearable

Instead of doing long problems you can move on to working one particular hard move that might not be hard on fingers but imposes different kind of challenge (splits, core strength, balance etc).

Take care and stay healthy

Always stop climbing before you damage your fingertips permanently. Watch out for those red spots on your fingertips, that's a bad sign! Stop right there.
Use "Climb On" and/or some nourishing hand cream after the climb.
Buy and drink fish oil capsules - those help your nails/hair and skin to grow.

Maintenance

Don't forget to climb at least 2 times a week to maintain thickness and in-sensitiveness of your finger skin!


Good luck my friend!

Monday 2 July 2012

GDAL usage examples

Some examples of how to use GDAL utility.

Georeference an image:
gdalwarp -te 385300 254100 385400 254200 in.tif out.tif

Export JPEG with RGB channels:
gdal_translate -ot byte -of JPEG -expand rgb in.tif rgb_out.jpg

Force to create TFW for this JPEG file (now it is georeferenced), although previous example also created TFW file by default:
gdal_translate -ot byte -of JPEG -expand rgb -co TFW=YES in.tif jpeg_with_tfw_out.jpg

Correct georeferenced tif by modifying coordinate information:
gdal_translate -a_ullr 385300 254200 385400 254100 -ot byte -of GTiff -co TFW=YES -co NBITS=1 -co COMPRESS=LZW in.tif out.tif

Export regular geotiff (this is a large file):
gdal_translate -ot byte -of GTiff -expand rgb in.tif expanded_geotiff_out.tif

Create LZW copressed geotiff:
gdal_translate -ot byte -of GTiff -co COMPRESS=LZW in.tif compressed_geotiff_out.tif

Export LZW compressed and 1 bit geotiff:
gdal_translate -ot byte -of GTiff -co NBITS=1 -co COMPRESS=LZW in.tif one_bit_geotiff_out.tif

ZLEVEL=9 - set compression level for DEFLATE:
gdal_translate -ot byte -of GTiff -co NBITS=1 -co COMPRESS=DEFLATE -co ZLEVEL=9 in.tif gtiff_with_custom_compress_out.tif

Tiled tiff file:
gdal_translate -ot byte -of GTiff -co NBITS=1 -co COMPRESS=DEFLATE -co ZLEVEL=9 -co TILED=YES in.tif tiled_geotiff_out.tif

Friday 29 June 2012

Geodesy

Coordinate Reference System (CRS)

A coordinate reference system  is a coor-dinate system which is referenced to the earth. CRS is one part of SRS. 

Spatial Reference System (SRS)

A reference system that defines coordinate reference system, datum using ellipsoid and either a geocentric, geographic or projection coordinate system.


Geographic Coordinate System (GCS)

A geographic coordinate system (GCS) uses a three-dimensional spherical surface to define locations on the earth. A GCS is often incorrectly called a datum, but a datum is only one part of a GCS. A GCS includes an angular unit of measure, a prime meridian, and a datum (based on a spheroid).

Geoid

Geoid is gravitational surface of the earth which approximetes mean sea level.

Ellipsoid

Ellipsoid is locally best fitting elliptic 3D approximation of the earth's surface.

In geodesy only 2 axis (in equatorial radii?) are considered:
  • semi-major axis (a)
  • semi-minor axis (b)
In geodesy though ellipsoid is quite often described with these two paramters:
  • semi-major axis (a)
  • inverse flattening 1/f where f is a ratio of:
    f = (semi-major - semi-minor)/semi-major axis )
the third axis (c or Z) is ignored.

Spheroid

Spheroid  is a type of ellipsoid where semi-minor axis = sami-major axis (a =b).
Oblate spheroid is a spheorid where c < a, the Earth is an oblate spheroid.

Geodetic Datums

A geodetic datum defines the position and orientation of the reference ellipsoid relative to the centre of the earth, and the meridian used as zero longitude – the prime meridian. 

In short, datum is the shift of a spheroid, it is a point where spheroid touches the surface of the earth. Each spheroid has several datums.


Geodetic datum transformations include:
  • shifts: dX, dY, dZ
  • scaling
  • rotations: X, Y, Z

Spatial Reference System usually has:

  • SRS name
  • unit type
  • mapping projection parameters:
    • projection name
    • latitude of origin
    • central meridian
    • scale factor
    • false easting
    • false northing
  • geographic CRS parameters:
    • CRS name
    • datum name
    • Pprime meridian related info:
      • name
      • longitude
    • spheroid related info:
      • name
      • semi-major axis
      • semi-minor axis
      • inverse flattening