GDAL/OGR uses the Proj.4 coordinate transformation library, 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. USeful references:
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 - see blogpost on how transformations are chosen in Proj4. 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
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 - see general parameters.
To change the transformation that is used by default to a 7 parameter shift do the following:
OGR/GDAL uses the file called GCS.csv in the gdal_data directory.
Open this file and search for 4277 (it will say OSGB 36) next to it.
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
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
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 the OSTN02 transformation in OGR/GDAL then you can do this from the command line.
Download the grid shift file from Ordnance Survey.
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).
Make sure the variable PROJ_LIB is set to the folder that contains the grid file or override the location by specifying it explicitly.
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.
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
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
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
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.
We use cookies for security purposes, remembering your preferences and to analyse site traffic in order
to improve your experience using the service. This includes anonymised Google Analytics data.
We won't share your data with anyone else.
For more information please see our
Cookie Policy page.