Main Content

Conversion of OSI grid references to Eastings and Northings

Archive - Originally posted on "The Horse's Mouth" - 2009-01-28 07:46:29 - Graham Ellis

In both Ireland and the UK, the Ordnance survey divides down the country into a series of lettered 100km x 100km squares, represented by 1 letter (Ireland) or 2 (UK mainland), and then measures / reports and Easting / Northing within that square.

Example:
ST645332 (UK, box ST, 64.5 km east, 33.2 km north)
J665543 (Ireland, box J, 66.5 km east, 54.3 km north)

For Graphic Information systems and for other comparisons, there's a need to remove the letter and add extra numbers onto the Easting and Northing to produce a pair of system wide co-ordinates, and due to the lack of a pattern in the letters, that's typically done with a lookup table.


Yesterday, I wrote a python program to do the conversion ...
Dorothy:d2 grahamellis$ ./irish_grid G552844
155200 384400 G552844
Dorothy:d2 grahamellis$

... which also handles a whole load of other formats (and reports to two more significant figures)


You are welcome to view / copy / use that program [source code here] which is an excellent expression of how regular expressions are used and captured in Python, and of course you are very welcome to come to our Python Course if you want to learn more about how to do this sort of thing yourself!

Illustration - Trim Castle [link]

P.S. Answer to a totally different question - look here for the class that lets you read Excel spread sheets into Python (Answer for course delegate!)