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


No comments: