Terms:

1. British National Grid – OSGB36 datum, ellipsoid: Airy 1830 ellipsoid (WKID: 27700, EPSG:27700)

2. Great Britain OSGB36 – OSGB36 datum, ellipsoid: Airy 1830 ellipsoid (WKID:4277, EPSG:4277)

4. ETRS89 – European Terrestrial Reference System 1989 – Datum ellipsoid: GRS80 – A high-accuracy version of WGS84. (Zone 28 WKID: 25828, Zone 29 WKID: 25829, Zone 30 WKID: 25830) 5. WebMerkator (Auxiliary Sphere) – used by Bing Maps, Google Maps an Open Street Map: – WKID: 102113 – First used then replaced by 102100 – (deprecated) – WKID: 102100, EPSG:3785 – (deprecated) – WKID:3857, EPSG:3857 since v.10 of ArcGIS Server – replaced ESRI WKID:102100 with this (

**current**) I decided to write this article as in my work (local authority) the 90% of the spatial data is created using British National Grid coordinate system.

Working with ArcGIS server there was never problem to display the data properly on the top of OS Mastermap or rasters, however few weeks ago I decided to do some mash up using the ArcGIS Java Script API and the basemap dijit and the problems jumped out.

I had to use the British National Grid data over the basemap having the WebMercator projection or a basemap coming from the basemap gallery (You can see it working here).

According to the ArcGIS JavaScript API help, the map’s spatial reference is based on the first layer added to the map and it cannot be overridden (source).

Exactly the same problem you can see when you try to export the features using ArcGIS Server REST API to KML. If you display that data over the WGS84 base map like Google maps you will notice the shift of approximately 100m (datum shift).

See the live example of the problem

The ‘datum shift’ was exactly the origin of the problem. The fact that British National Grid is Transverse Mercator projection (with origin at 49°N, 2°W) based on the Airy 1830 ellipsoid using and WGS84 is based on different GRS80 ellipsoid means the coordinates cannot be transformed directly between those two projections.

An intermediate step is needed for that transformation and before you start converting coordinates I would strongly recommend to read the document below. It’s very simple and clear explanation why we need to transform the coordinates and what is currently possible.

Ordnance Survey Guide – Must read

So, after the above lecture you should have quite good understanding of the problem :).

Let’s have a look at some sample point data.

Sample British National Grid point:

Easting: 420000

Northing: 160000

The correct conversion using OS coordinate transformer service (http://gps.ordnancesurvey.co.uk/convert.asp):

Looks like there will be no problem with this conversion at Version 10.1 of ArcGIS Server the REST Interface of Geometry Server is updated to include **Datum Transformation**. at 10.1 the OSTN02 NTv2 Transformation is available as EPSG:5339, see below.

However if you need to have a transformation, which one does between WGS 1984 and British National Grid, then SOAP is the only way before the release of Version 10.1. The result from ArcGis 9.3.1 transformation is shown below:

The transformation is wrong, as you can see there is a significant difference in the output X and Y as the transformation does not include the Datum change.

## Manual solution:

The definitive transformation from ETRS89 that is published by the OSGB is called the National Grid Transformation OSTN02. This models the detailed distortions in the 1936–1962 retriangulation, and achieves backwards compatibility in grid coordinates to sub-metre accuracy.

However for the purposes of displaying not sensitive data data over the web we can use the second method – the Helmert transformation.

For the transformation from OSGB36 to WGS84 in Britain, using a single Helmert transformation will give errors of up to 5 metres, depending where in the country the points of interest are. One solution to this is to compute a special set of Helmert parameters for a particular region – this is known as a ‘local transformation’.

Alternatively, more complex transformation types that model TRF distortion can be used. An example

of this is the National Grid Transformation OSTN02.

To summarise: For a simple datum change of latitude and longitude coordinates from datum A to datum B, first convert to Cartesian coordinates, taking all ellipsoid heights as zero and using the ellipsoid parameters of datum A; then apply a Helmert transformation from datum A to datum B using equation:

finally convert back to latitude and longitude using the ellipsoid parameters of datum B, discarding the datum B ellipsoid height.

In our case as we have initial coordinates in British National Grid we need to do some more steps:

1. Convert easting and northing to Lat, Lon based on OSGB36 datum,

2. Convert polar lat/long/height φ, λ, H to cartesian co-ordinates x, y, z (using the source ellipse parameters),

3. apply 7-parameter Helmert transformation; this applies a 3-dimensional shift, rotation, and scale,

4. convert cartesian co-ordinates back to polar (using the destination ellipse parameters – GRS80).

### Convert British National Grid to WGS84 – Java Script Solution

To do all these conversion we can use Java Script functions written by Chris Veness – his two documents:

1.Convert co-ordinates between WGS-84 and OSGB36 and

2.Convert between Latitude/Longitude & OS National Grid Reference points

are presenting the methodology and logic used during the coordinate conversion.

[Download slightly modified conversion script – cords_convert.js]

The further conversion from WGS84 to WebMerkator (WKID: 102100) can be achieved using the ArcGIS Server, JavaScript API method or using this short Java Script function:

function LatLonWGS84ToWebMercator(wgs84lat, wgs84lon) { if((Math.abs(wgs84lon)>180|| Math.abs(wgs84lat)>90)){return;} var rMajor = 6378137; //Equatorial Radius, WGS84 var num = whs84lon * 0.017453292519943295; var x = rMajor *num; var a = wgs84lat * 0.017453292519943295; var mercatorX = x; var mercatorY = 3189068.5 * Math.log ((1.0 +Math.sin(a))/(1.0-Math.sin(a))); return { 'MercatorX': mercatorX, 'MercatorY':mercatorY}; }

### Convert British National Grid to WGS84 – Python Script Solution

You need to install the **pyproj library** – Download

import pyproj# Define two projections, one for the British National Grid and one for WGS84 (Lat/Lon)

# You can use the full PROJ4 definition or the EPSG identifier (PROJ4 uses a file that matches the two)

#bng = Proj(“+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs towgs84=’446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894′”)

#wgs84 = Proj(‘+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs’)

bng = pyproj.Proj(init='epsg:27700') wgs84 = pyproj.Proj(init='epsg:4326') lon,lat = pyproj.transform(bng,wgs84,275331.897,657213.866)# lon,lat should be now -3.989913896812542, 55.792093458315854

# which is the centre of the roundabout in Motherwell (Merry Street) :

# http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=55.792093458315854,-3.989913896812542

C:\Python26\ArcGIS10.0>python Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pyproj >>> bng=pyproj.Proj(init='epsg:27700') >>> wgs84 = pyproj.Proj(init='epsg:4326') >>> lon,lat = pyproj.transform(bng,wgs84,439725,557002) >>> lat 54.906163255053876 >>> lon -1.3819797470583637 >>> lon,lat = pyproj.transform(bng,wgs84,275331.897,657213.866) >>> lon -3.989913896812542 >>> lat 55.792093458315854 >>>

I hope you have found this article useful, please note I am not coordinate system expert and was only adopting some solutions and written this article as there is not much about that so you have few useful links in one place.

Any comments or questions are welcome.

I am sorry the live example was not working properly in Fire Fox, now the bug is fixed….

Hi,

I am using Arcgis 10.2.1.But still i am seeing shift.

Can you please help me?

thanks in advance.

Thanks,

Anuj

Hi, I do not have ArcGIS Software at home, I am back to work next week – will check it out (didn’t do any conversions for a while now). Do you need the conversion working for ArcGIS Server or Desktop?

Hi,

I am having data in BNG projection. Earlier I was using ArcGIS 9.3.1 but I was seeing data shifting on GOOGLE map. As you mentioned in your article “there will be no problem with this conversion at Version 10.1 of ArcGIS Server the REST Interface of Geometry Server is updated to include Datum Transformation.” So I have upgraded my ArcGIS 9.3.1 to ArcGIS 10.2.1.

I want to display BNG data over Google MAP.

Please let me know you need any more information.

Can you please help me to resolve this issue?

Thanks,

Anuj Katiyar

Hi, you need to publish your service with the data converted from BNG (WKID:27700) to WebMercator (WKID:3857) or to (WGS84 – WKID:4326) using Datum transformation 5339.

Before you can use 5339 datum transformation you need to download OSTN02_NTv2.gsb from http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/navigation-technology/os-net/ostn02-ntv2-format.html then paste the file into C:\Program Files\ArcGIS\Server\pedata\ntv2\uk folder (if does not exist just create it) on the machine with ArcGIS Server installed.

Ones the file is there, restart ArcGIS Server service – the transformation should work fine since that. I have tested it with ArcGIS Server 10.1 – do not have 10.2 software available yet.

Kind Regards,

Andrzej

Hi,

I tried below steps but still i am seeing same shift.i ahve pasted OSTN02_NTv2.gsb file as suggested by you.

i am using below steps.

1.open Arcmap and add bng data.

2.After that i have changed the data frame coordinate system to wgs 1984 Web mercator (Auxiliar sphere).

3.Applied transformation using OSGB_1936_TO_WGS_1984_Petroleum.

4.Created new service.

But still i am seeing same shift.

Can you please help me?

Thanks,

Anuj Katiyar

The solution I have posted above will works only for ArcGIS Server REST access to Geometry service, it will not work for Desktop. To add OSTN02 conversion support for desktop please copy and paste file from OS (OSTN02_NTv2.gsb) into:

C:\Program Files (x86)\ArcGIS\Desktop10.1\pedata\ntv2\uk

Then reopen ArcMap and as a transformation use not Petroleum but:

OSGB_1936_To_ETRS_1989_1 + ETRS_1989_To_WGS_1984 – this will be new position on the transformation dropdown.

Please email me at osedok@gmail.com – so I will be able to send you some screenshots.

Regards,

Andrzej

Hi,

As suggested by you i have tried but still same problem.

Can you please email me at anuj028.kiit@gmail.com for any other steps.

Thanks,

Anuj Katiyar

Hi

I need to use BNG Coordinates in web app builder.So can you please tell me how to convert geographical coordinates system to BNG coordinates in web app builder

HI Saurabh,

If your base map (tiled map service) is set to WKID 27700 the coordinates widget will be showing the BNG coordinates automatically. I am not sure if that’s what you are looking for?

Thanks for your response

But I am new to use web app builder. So if you elaborate this more then it will be good for me.

Hi

I want to make a widget for WGS84 TO BNG convertion system.Can you tell me the way to do it?

Hi Saurabh,

I believe the coordinate widget available in ArcGIS Online WebApp Builder supports the coordinates conversion out of the box, you can specify the input and output coordinate system as well as the datum transformation method if required (as it is in case of converting WGS84 to BNG).

I am out of office right now, but I may provide more specific answer to your question on Monday morning – but as far as I remember such conversion is possible out of the box.

Thanks for your response

But I am new to use web app builder. So if you elaborate this more then it will be good for me.

I will see what I can do for you on Monday. You may also find some more details on esri official site: https://doc.arcgis.com/en/web-appbuilder/create-apps/widget-coordinates.htm