Tag Archives: ordnance-survey

Convert Latitude Longitude to Easting Northings

Take a look and hopefully it works in your code.


private double toRad(double val)
{
	return val * (Math.PI / 180);
}
        
public void LatLongToEastNorth(double latitude, double longitude)
{
       //This will not work unless you have your lats and longs in decimal degrees.
       latitude = toRad(latitude);
       longitude = toRad(longitude);

       double a = 6377563.396, b = 6356256.910; // Airy 1830 major & minor semi-axes
       //double a = 6378137.0, b = 6356752.314245; WGS84 major & minor semi-axes

       double F0 = 0.9996012717; // NatGrid scale factor on central meridian
       double lat0 = toRad(49);
       double lon0 = toRad(-2); // NatGrid true origin
       double N0 = -100000, E0 = 400000; // northing & easting of true origin, metres
       double e2 = 1 - (b * b) / (a * a); // eccentricity squared
       double n = (a - b) / (a + b), n2 = n * n, n3 = n * n * n;

       double cosLat = Math.Cos(latitude), sinLat = Math.Sin(latitude);
       double nu = a * F0 / Math.Sqrt(1 - e2 * sinLat * sinLat) ; // transverse radius of curvature
       double rho = a * F0 * (1 - e2) / Math.Pow(1 - e2 * sinLat * sinLat, 1.5); // meridional radius of curvature
   
       double eta2 = nu / rho - 1;

       double Ma = (1 + n + (5 / 4) * n2 + (5 / 4) * n3) * (latitude - lat0);
       double Mb = (3 * n + 3 * n * n + (21/8)*n3) * Math.Sin(latitude - lat0) * Math.Cos(latitude + lat0);
       double Mc = ((15/8)*n2 + (15/8)*n3) * Math.Sin(2 * (latitude - lat0)) * Math.Cos(2 * (latitude + lat0));
       double Md = (35 / 24) * n3 * Math.Sin(3 * (latitude - lat0)) * Math.Cos(3 * (latitude + lat0));
       double M = b * F0 * (Ma - Mb + Mc - Md); // meridional arc

       double cos3lat = cosLat * cosLat * cosLat;
       double cos5lat = cos3lat * cosLat * cosLat;
       double tan2lat = Math.Tan(latitude) * Math.Tan(latitude);
       double tan4lat = tan2lat * tan2lat;

       double I = M + N0;
       double II = (nu / 2) * sinLat * cosLat;
       double III = (nu / 24) * sinLat * cos3lat * (5 - tan2lat + 9 * eta2);
       double IIIA = (nu / 720) * sinLat * cos5lat * (61 - 58 * tan2lat + tan4lat);
       double IV = nu * cosLat;
       double V = (nu / 6) * cos3lat * (nu / rho - tan2lat);
       double VI = (nu / 120) * cos5lat * (5 - 18 * tan2lat + tan4lat + 14 * eta2 - 58 * tan2lat * eta2);

       double dLon = longitude - lon0;
       double dLon2 = dLon * dLon, dLon3 = dLon2 * dLon, dLon4 = dLon3 * dLon, dLon5 = dLon4 * dLon, dLon6 = dLon5 * dLon;

       double N = I + II * dLon2 + III * dLon4 + IIIA * dLon6; //This is the northing
       double E = E0 + IV * dLon + V * dLon3 + VI * dLon5; //This is the easting  
}
Advertisements

Update: Bing Maps and Ordnance Survey data in ArcGIS Server 9.3.1

Apparently it is a known problem for OS data to not line up with Bing Maps service and in order to get round this you have to re-project all your British National Grid data to the WGS 1984 Web Mercator (Auxiliary Sphere) coordinate system.  How rubbish is that!

Anyway this problem is apparently known to ESRI and it is apparently fixed in verison 10 (it was tested by ESRI support in a beta 10 version).  So I guess we will have to wait until thats out and a few service packs have been released until we can feel confident with rolling out version 10.

On that note I’ll talk about this issue in about another year to 18 months (I would have thought!)

Projecting Bing Maps and Ordnance Survey Data in ArcGIS Server

(Using ArcGIS Server 9.3.1.)

Creating an mxd in ArcMap with some Mastermap data and then publish this with a Bing Maps Layer in AGS Manager will cause the Mastermap data to not line up with the imagery.

  • Bing Maps service is served up in projection system – WGS 1984 Web Mercator.
  • MasterMap is in British National Grid coordinate system.

One way of definitely getting the data to line up is to use the Project tool in ArcToolbox.  This will change the actual coordinates of the data to “transform” from OS Grid to WGS84 coordinates.  You may find however that this is creates a lot of overhead to keep updating your datasets to WGS84 – especially if they are dynamic layers rather than static background mapping.

I am still researching a better way to try to solve this problem.

null