Movable Type Home Page

Movable Type Scripts


Convert co-ordinates between WGS84 and OSGB36

Before I started writing these geodesy scripts, I assumed a lat/long point was a lat/long point, and that was it. Since then, I have discovered that – if you’re being accurate – you need to know what datum you are working within.

In the UK, a latitude/longitude point in WGS84 (as generally used by GPS systems or any world-wide reference system) can be over 100 metres from the same latitude/longitude point in OSGB36 (as used in all Ordnance Survey mapping). The exact difference varies according to location. If you are using Vincenty formulae for calculating distances between points on an ellipsoidal model of the earth, these differences can become relevant.

Note: this is why the Greenwich Meridian shows up about 100 metres from the 0° meridian on GPS units: try 51°28′39″N, 000°00′00″W  as an OSGB36 point...

Functional demo
Latitude Longitude
WGS84
OSGB36

To convert between datums, a ‘Helmert transformation’ is used. The Ordnance Survey explain the details in section 6 (and the annexes) of their Guide to coordinate systems in Great Britain.

The procedure is:

  1. convert polar lat/long/height φ, λ, H to cartesian co-ordinates x, y, z (using the source ellipsoid parameters)
  2. apply 7-parameter Helmert transformation; this applies a 3-dimensional shift, rotation, and scale
  3. convert cartesian co-ordinates back to polar (using the destination ellipsoid parameters)

1 convert polar co-ordinates to cartesian:

e² = (a²−b²) / a² (eccentricity of source ellipsoid ) (B1)
ν = a / √(1−e² · sin²φ) (transverse radius of curvature) (B2)
x = (ν+H) · cosφ · cosλ (B3)
y = (ν+H) · cosφ · sinλ (B4)
z = ((1−e²) · ν+H) · sinφ (B5)

2 apply Helmert transform

The Helmert transform is given by:

transform matrix

Hence:

x′ = tx + (1+s) · x rz · y + ry · z
y′ = ty + rz · x + (1+s) · y rx · z
z′ = tzry · x + rx · y + (1+s) · z

3 convert cartesian co-ordinates back to polar

e² = (a²−b²) / a² (eccentricity of destination ellipsoid) (B1)
p = √(x² + y²) (B7)
φ = atan2(z, p · (1−e²)) (initial value) (B7)
iterate until change in φ is negligible { Helmert transform is good to a few metres between WGS84 & OSGB36
ν = a / √(1−e² · sin²φ)
φ′ = atan2(z + e² · ν · sinφ, p) (B8)
}
λ = atan2(y, x) (B6)
H = p / cosφ − ν

A single Helmert transformation is accurate to within about 4–5 metres (between WGS84 and OSGB36) – for greater accuracy, a ‘rubber-sheet’ style transformation, which takes into account distortions in the ‘terrestrial reference frame’ (TRF), must be used: if you’re learning anything from this page, you don’t want even to think of going there...

For other scripts for calculating distances, bearings, etc between latitude/longitude points, see my Lat/Long page. I have also done a script for converting between (OSGB36) lat/long and OS grid references.


See below for the source code of the JavaScript implementation, also available on GitHub. These functions should be simple to translate into other languages if required, though the object literal notation (used for ellipsoid & transform parameters) is particularly concise in JavaScript.

The code below will convert between WGS84 and a number of other datums. To extend the list of conversions, you just need the ellipsoid and Helmert transform parameters.

Creative Commons License I offer these formulæ & scripts for free use and adaptation as my contribution to the open-source info-sphere from which I have received so much. You are welcome to re-use these scripts [under a simple attribution license, without any warranty express or implied] provided solely that you retain my copyright notice and a link to this page.

If you would like to show your appreciation and support continued development of these scripts, I would most gratefully accept donations.

If you need any advice or development work done, I am available for consultancy.

If you have any queries or find any problems, contact me at ku.oc.epyt-elbavom@oeg-stpircs

© 2006-2014 Chris Veness