Posted by: benismobile | April 1, 2010

Convert to and from OS National Grid


As we expect many folk to be playing with the new OS Open datasets we thought we’d share some javascript code that we have been using to convert from WGS84 lat/long coordinates to the British National Grid. We ported this from existing Java code we know is sound. The Javascript version works ok but there are some rounding errors as can be seen from this test, which converts from a lat, lon to National Grid, then back again. Good enough for most mobile apps we think but use at your own risk as its not fully tested.

Some example code to convert your GPS fix to NG coordinates:

var natgrid =  new Edina.EPSG_27700() ;
var coords ;
coords = natgrid.toLocalSystem( latt, lont );
document.getElementById('northing').innerHTML="northing: " + coords[0] ;
document.getElementById('easting').innerHTML="easting:   " + coords[1] ;

Advertisements

Responses

  1. the GIS experts I work with think the rounding error equates to 10cm.

  2. […] low level functions to cope with this projection. We had to use our own javascript utilities (the coordamatic library) for unit and projection changes to get it working […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: