Transformations to OSGB36 and WGS84 in GDAL/OGR

GDAL/OGR uses the Proj.4 coordinate transformation library (https://github.com/OSGeo/proj.4/wiki), for instance when using ogr2ogr. QGIS, PostGIS and other open source and commercial software also use PROJ.4 as the basis for their transformation engines so you will need to check what transformation they are using [9,10].

PROJ.4 contains a large number of transformations and parameters. However by default OGR uses a 3 parameter shift because it covers the largest available area [11]. However, this is only accurate to +/- 20 metres over the whole of the UK. It is equivalent to the ArcGIS transformation called OSGB_1936_To_GS_1984_1 and has parameters of dX: 375, dY-111, dZ 431

This can be seen in the file gdal_data/datum_shift.csv in the GDAL installation directory.

Next to the CRS code 4277 (the EPSG code for OSGB36) there are a number of entries. The 3 parameter shift is the ‘preferred’ one so it will be used by default. The more accurate 7 parameter one is listed but not used by default.

To run this 3 parameter shift from the command line use the following:

ogr2ogr -t_srs EPSG:4326 -s_srs "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +towgs84=375,-111,431" d:\data\test\coords\mm_shape\Topo_Line_wgs84_3p.shp d:\data\test\coords\mm_shape\Topo_Line.shp

How to select a different transformation

Either a more accurate 7 Parameter transformation should be used or the OSTN02 shift should be used, both of which are supported by Proj.4 [12].

To use 7-Parameter Shift

To change the transformation that is used by default to a 7 parameter shift do the following:

a) OGR/GDAL uses the file called GCS.csv in the gdal_data directory.

b) Open this file and search for 4277 (it will say OSGB 36) next to it.

c) Edit the file so that the entry for 4277 is:

4277,OSGB 1936,6277,OSGB 1936,6277,9122,7001,8901,1,0,6422,1195,1,9603,446.448,-125.157,542.060,0.150,0.247,0.842,-20.489

d) Ensure that the last 7 values are (ensuring the sign of all values is correct):

446.448,-125.157,542.060,0.150,0.247,0.842,-20.489

You can also specify the transformation from OSGB36 to WGS84 on the command line, as follows:

ogr2ogr -t_srs EPSG:4326 -s_srs "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 " d:\data\test\coords\mm_shape\Topo_Line_wgs84_7p.shp d:\data\test\coords\mm_shape\Topo_Line.shp

The command to transform from WGS84 to OSGB36 is as follows:

ogr2ogr -s_srs EPSG:4326 -t_srs "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894" d:\data\test\coords\mm_shape\Topo_Line_osgb36_7p.shp d:\data\test\coords\mm_shape\Topo_Line_wgs84_7p.shp

 

To Use OSTN02

To use the OSTN02 transformation in OGR/GDAL then you can do this from the command line.

1) Download the grid shift file from Ordnance Survey.

- Available at: OSTN02 data file

2) Unzip and put the gsb file into the ‘projlib’ folder in the GDAL installation (or somewhere else but you will need to specify the location).

3) Make sure the variable PROJ_LIB is set to the folder that contains the grid file or override the location by specifying it explicitly.

4) Turn on debugging initially (set PROJ_DEBUG=true) to make sure it is finding the grid file as it will appear to work even if it doesn’t find the file and will use the 3 parameter shift instead.

5a) The command to use the grid to convert from OSGB36 to WGS84 is like the following:

ogr2ogr -s_srs "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +nadgrids=d:\ostn02_ntv2.gsb" -t_srs EPSG:4326 d:\data\test\coords\mm_shape\Topo_Line_wgs84_ostn02.shp d:\data\test\coords\mm_shape\Topo_Line.shp

5b) The command to convert from WGS84 to OSGB36 is like the following:

ogr2ogr -t_srs "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +nadgrids=d:\ostn02_ntv2.gsb" -s_srs EPSG:4326 d:\data\test\coords\mm_shape\Topo_Line_osgb36_ostn02.shp d:\data\test\coords\mm_shape\Topo_Line_wgs84_ostn02.shp

 

Results

The following diagram shows the effect of all 3 transformations on an area in Edinburgh.

The black lines are data transformed using OSTN02, the red lines are using the 7-Parameter OS shift and the green lines show the default OGR 3 parameter shift.

OSTN02 à 7 Parameter delta=0.5m

OSTN à3 Parameter delta=5m

Figure 6: Comparison of 3p, 7p and OSTN02 transformations

Summary

If using PROJ.4 based transformations (either in OGR/GDAL or QGIS) you should use the OSTN02 grid file if possible. If not then either change the default transformation to use the 7-Parameter OS transformation or specify the 7 Parameter transformation on the command line.

 

References

[1] eLearning module on Coordinate systems and projections: http://digimap.edina.ac.uk/webhelp/training/training.htm#elearning/eLearning.htm

[2] Ordnance Survey – A Guide to coordinate systems in Great Britain

http://www.ordnancesurvey.co.uk/docs/support/guide-coordinate-systems-great-britain.pdf

[3] Seazone: Introduction to Coordinate Reference Systems

http://www.seazone.com/help-support/SeaZone_Introduction-to-coordinate-reference-systems.pdf

[4] Coordinate Systems in FME: https://knowledge.safe.com/articles/585/using-coordinate-systems-within-fme.html

[5]Geotrans Geographic Translator

http://earth-info.nga.mil/GandG/geotrans/

[6]Defining Coordinate Systems in FME: http://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Coordinate_Systems/Home_cs.htm

[7]Esri UK – Understanding which Transformation to Choose in ArcGIS: http://communityhub.esriuk.com/journal/2012/3/26/coordinate-systems-and-projections-for-beginners.html

[8] Esri UK – What are my OGC web services displaced by about 120m?:  http://communityhub.esriuk.com/journal/2012/10/12/why-are-my-ogc-web-services-displaced-by-about-120-metres.html

[9] Other information about implementing OSTN02 in PostGIS directly is available here:

http://blog.mackerron.com/2012/07/03/ostn02-for-postgis/

[10] Information about transformations in QGIS

http://gis.stackexchange.com/questions/76411/issues-using-geographic-and-projected-coordinate-systems-qgis-2-0

[11] Blog from Frank Warmerdam indicating how transformations are chosen in proj.4

http://fwarmerdam.blogspot.co.uk/2010/03/in-last-few-weeks-i-believe-i-have-made.html

[12] PROJ.4 General Parameters

http://trac.osgeo.org/proj/wiki/GenParms#nadgrids-GridBasedDatumAdjustments