Ordnance Survey locations

Converting between OS grid references and longitudes-latitudes.

The Ordinance Survey is a UK-peculiar geospatial format, ubiquitous via street atlases, hiking charts and (yes) farming and epidemiological maps. It is explained in great detail is several places, but here's a quick overview:

The OS grid is a set of 25 squares, 500 kilometers a side, arranged 5-by-5 that is superimposed over the UK. These squares are addressed A to Z, excluding I, running west-to-east, north-to-south like so:


In reality, only H, J, N, O, S & T are used, as they cover the mainland UK and most of the prominent islands. These 500km squares are broken own again into 25 squares, 100 kilometres a side, arranged 5 by 5 as above. Within each of these minor squares, a position can be given as an east-north within that square, from its south-west corner. These are typically given as 3 digits each, so the lowest digit represents 100 metres. Thus 114 525 is 11.4 kilometers east and 52.5 kilometres north of it's containing square. So a point just outside Ipswich (in south-east England) can be given as TM 114 525. (That is, 500km square T, 100km square M, 11.4 kilometers east and 52.5 kilometres north of the south-west corner of M.)

Of course, there are complications. Formatting is variable, with the spaces sometimes omitted from the reference:

TM 114 525
TM114 525
TM 114525

It's unclear which, if any, is the canonical form. Further more, the eastings-northings can be given in higher resolutions up to 6 digits each, where the final digit represents 10cm. Therefore these all map to the same point:

TM 114 525
TM 1140 5250
TM 114000 525000

Converting these to a more widely-used coordinate system is non-trivial. First, the OS system is a true grid (i.e. square) unlike the conventional lon-lats that are squeezed by the earths shape. The OS grid is anchored to the conventional coordinates, at a point near the Channel Isles, but this point is projected so that all coordinates in the UK can be referred to with positive eastings-northings.

Finally, the OS references are based on the OS1936 global projection, not the WGS84 or ETR projections. In plain English, these are models of the world's shape - the height and width of the ellipsoid - that the lon-lat grid is laid over. As a consequence, lon-lats in either system will disagree with the other, although perhaps only by metres.

Right, now we can look at converting this with Python, elsewhere.