ITM <-> WGS84 (<-> Irish Grid <-> British National Grid) PHP code

With Ireland soon to be moving to ITM (Irish Transverse Mercator) coordinates, over IG (Irish Grid) that has been used since about 1965 in Ireland, many websites – including Geograph.ie and nearby.org.uk will be looking to support ITM coordinates – even if they still use Irish Grid.

So to that end have been looking for PHP code to do the conversion, but thanks to a little bit of inspiration from FieldenMaps.info’s Javascript Ireland Coordinate Converter (an excellent resource in its own right!), realised it would be simple to add to the conversion class we already use. In fact as ITM is based on GRS80 which is effectivly WGS84 the conversion was just a matter of plugging in the constants used by ITM, and the code just worked.

Better yet as Geograph is Open Source (and we got permission to open source the code based on OSGB’s conversion spreadsheet), the code is available for anyone to use as a PHP class. It should be trivial to add support to our Javascript class – which will do shortly!

Grab the class from Geograph SVN (or even better do a SVN checkout!) and put it somewhere safe. (but you will probably want to remove the “extends Conversions” bit from the definition – we use that for convience in Geograph source)

Then can just use it

$conv = new ConversionsLatLong;
list($lat,$lng) = $conv->itm_to_wgs84($e,$n);

But as we already use the same code for Irish Grid, and OSGB36 British National Grid, can also use it for them, and even IG< ->ITM conversion

list($lat,$lng) = $conv->itm_to_wgs84($e,$n);
list($lat,$lng) = $conv->irish_to_wgs84($e,$n,true);
list($lat,$lng) = $conv->osgb_to_wgs84($e,$n);

list($e,$n) = $conv->wgs84_to_itm($lat,$lng);
list($e,$n) = $conv->wgs84_to_irish($lat,$lng,true);

list($e,$n) = $conv->wgs84_to_osgb36($lat,$lng);
//even a short convience function to create a 10 figure grid reference
$gr10 = $conv->osgb36_to_gridref($e,$n);

See it used in anger here and here.

Comments are closed.