GPStoOSGB library - UK specific!

agraham

Expert
Licensed User
Longtime User
This simple(!) library converts from WSG84 latitude and longitude values, as usually returned by GPS receivers, to OSGB36 values as used by the Great Britain Ordnance Survey and printed on OS maps, and then on to OS National Grid map references. The reverse process is also supported.

For those who don't know the OS is Great Britains national mapping and survey service and is the primary source of map data for the UK. Ordnance Survey, Britain's national mapping agency

Help is in the demo and source is included for merging. Runs under .NET 1.0/1.1 or later on device and desktop.

EDIT :- Version 1.2 posted. ODN height added and more help in the demo. See post #4 below.
 

Attachments

  • GPStoOSGB1.2.zip
    9.7 KB · Views: 124
Last edited:

agraham

Expert
Licensed User
Longtime User
I'm pretty sure you could also use GPS.ChangeDatum to do it.
It could but I think this library is more accurate as it uses a 7 parameter Helmert transformation (I don't really know what that means :) but the source code contains the URL of the website that I obtained the code from that initially came from the OS documentation). It could even be a bit more accurate as the algorithm also includes ellipsoid height but I've set that to zero for convenience as it has a really minor effect below the levels at which aircraft fly. The library round trips from WSG84 through OSGB36 to National Grid and back with remarkable accuracy.

Actually the major feature of the library is the transformation to the OS National Grid Reference which is the primary way that map locations are specified in the UK. We don't use lat/long we use the National Grid and it is printed on all OS maps as a grid as the primary location mechanism. Lat/long is included but only as small crosses at spot points for cross reference to the grid.

EDIT:- I've done the comparison and the difference for locations near to me is about 3 metres in both directions between the 7 parameter Helmert transormation from the Ordnance Survey documentation and whatever the transformation implemented in the GPS Converter is. You've got to get the signs of the dx,dy and dz correct though!
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Altitudes on UK maps are usually measured with reference to the mean sea level at the Newlyn Tidal Observatory. This level is called the "Ordnance Datum Newlyn" (ODN).

After some more research on the OS site version 1.2 of the library now returns an "approximation" (so termed by the OS literature!) of the ODN height from a WGS84/GPS ellipsoid altitude using an equation and parameters specified by the Ordnance Survey for that purpose.

This means that WGS84/GPS latitude longitude and ellipsoid height can now be translated into UK latitude, longitude, height and grid references as printed on UK Ordnance Survey maps.
 

mjcoon

Well-Known Member
Licensed User
I'm pretty sure you could also use GPS.ChangeDatum to do it.
You should follow the link on this page. This datum does appear in the table.

The datum change is only part of the process. OS-GB is a Transverse Mercator projection. Like UTM but using different parameters. In particular the base meridian is 2 degrees West so that similar areas of land are to East and West of that meridian.

I've only just discovered this library; it's one I've wanted for a while. (I implemented it myself, with help, years ago for my old Psion computers.)

Mike.
 

mjcoon

Well-Known Member
Licensed User
This simple(!) library converts from WSG84 latitude and longitude values, as usually returned by GPS receivers, to OSGB36 values as used by the Great Britain Ordnance Survey and printed on OS maps, and then on to OS National Grid map references. ...

I've just run the demo and noticed a trap for the unwary. It is customary to drop less-significant digits if a less accurate representation of a co-ordinate is satisfactory. However it is essential to retain the leading digit(s), even if they are zero. So in the attached initial MsgBox output the
B4X:
National Grid: 146750 28600
should really be
B4X:
National Grid: 146750 [COLOR="Red"]0[/COLOR]28600

It would be even worse of square SV had been chosen rather than SW because then both Easting and Northing would need leading zeroes.

Mike.

Edit: perhaps I'm wrong about the above, on the grounds that the eastings and northings are defined to be in metres and must always be shown separated by some non-numeric text, unlike the easting and northing parts of an alphanumeric grid reference.
 

Attachments

  • leading-zero.JPG
    leading-zero.JPG
    12.9 KB · Views: 7
Last edited:

agraham

Expert
Licensed User
Longtime User
Well spotted Mike. The Northing and Easting are actually returned as double values with an implicit significance of six digits so I guess that the display program should use Format(OSGB.Northing, "D6"), rather than just relying on the default format, and then truncate the right side of the string if necessary. Is this correct?
 

mjcoon

Well-Known Member
Licensed User
Well spotted Mike. The Northing and Easting are actually returned as double values with an implicit significance of six digits so I guess that the display program should use Format(OSGB.Northing, "D6"), rather than just relying on the default format, and then truncate the right side of the string if necessary. Is this correct?

Hi Andrew, I half-recanted per my Edit. But then saw on the MAGIC web site's Help text that they think the numeric form can validly be truncated in the same way as the alpha-numeric. Not as authentic as a statement on the Ordnance Survey web site but I couldn't find one of those...

BTW a Local Authority near here publishes grid references for planning applications with two decimal places!

Mike.
 
Top