Convert coordinates from Latitude/Longitude (WSG84) to Greek Grid (GGRS87 / ΕΓΣΑ87 / ESPG:2100)

kokyri's blog

tips, tutorials & samples for .NET, Windows Phone and Kinect developers

Convert coordinates from Latitude/Longitude (WSG84) to Greek Grid (GGRS87 / ΕΓΣΑ87 / ESPG:2100)

  • Comments 3
  • Likes
 
Below is an algorithm to convert coordinates to the greek grid system from the conventional WSG84 system. Check out http://geodesy.codeplex.com for a great open source library allowing you to convert between coordinate systems including the Greek Grid and compute geodetic projections for .NET, Silverlight and Windows Phone.
 
public static double[] ToGreekGrid(double lat, double lng)
        {
            lat = lat * Math.PI / 180;
            lng = lng * Math.PI / 180;
            var a = 6378137;
            var b = 6356752.31424518;
            var e2 = (Math.Pow(a,2) - Math.Pow(b,2)) / Math.Pow(a, 2);
            var v = a / Math.Sqrt(1 - e2 * (Math.Sin(lat) * Math.Sin(lat)));
            var X = v * Math.Cos(lat) * Math.Cos(lng);
            var Y = v * Math.Cos(lat) * Math.Sin(lng);
            var Z = (v * (1 - e2)) * Math.Sin(lat);
            var px = 199.723;
            var py = -74.03;
            var pz = -246.018;
            var rw = 0;
            var rf = 0;
            var rk = 0;
            var ks = 1;
            var c1 = Math.Cos(rw);
            var c2 = Math.Cos(rf);
            var c3 = Math.Cos(rk);
            var s1 = Math.Sin(rw);
            var s2 = Math.Sin(rf);
            var s3 = Math.Sin(rk);
            var D11 = c2 * c3;
            var D21 = -c2 * s3;
            var D31 = Math.Sin(rf);
            var D12 = s1 * s2 * c3 + c1 * s3;
            var D22 = -s1 * s2 * s3 + c1 * c3;
            var D32 = -s1 * c2;
            var D13 = -c1 * s2 * c3 + s1 * s3;
            var D23 = c1 * s2 * s3 + s1 * c3;
            var D33 = c1 * c2;
            var X1 = px + ks * (D11 * X + D12 * Y + D13 * Z);
            var Y1 = py + ks * (D21 * X + D22 * Y + D23 * Z);
            var Z1 = pz + ks * (D31 * X + D32 * Y + D33 * Z);
            lng = Math.Atan2(Y1, X1);
            var lat0 = Math.Atan2(Z1, Math.Sqrt(X1 * X1 + Y1 * Y1));
            b = 6356752.31414036;
            e2 = (Math.Pow(a, 2) - Math.Pow(b,2)) / Math.Pow(a, 2);
            while (Math.Abs(lat - lat0) > 0.0000000001)
            {
                var No = a / Math.Sqrt(1 - e2 * Math.Sin(lat0) * Math.Sin(lat0));
                var h = Math.Sqrt(X1 * X1 + Y1 * Y1) / Math.Cos(lat0) - No;
                lat = lat0;
                lat0 = Math.Atan(Z1 / Math.Sqrt(X1 * X1 + Y1 * Y1) * (1 / (1 - e2 * No / (No+ h))));
            }
            lng = lng - 24 * Math.PI / 180;
            var m0 = 0.9996;
            var es2 = (Math.Pow(a,2) - Math.Pow(b,2)) / (Math.Pow(b,2));
            var V = Math.Sqrt(1 + es2 * Math.Cos(lat) * Math.Cos(lat));
            var eta = Math.Sqrt(es2 * Math.Cos(lat) * Math.Cos(lat));
            var Bf = Math.Atan(Math.Tan(lat) / Math.Cos(V * lng) * (1 + eta * eta / 6 * (1 - 3 * Math.Sin(lat) * Math.Sin(lat)) * lng * lng * lng * lng));
            var Vf = Math.Sqrt(1 + es2 * Math.Cos(Bf) * Math.Cos(Bf));
            var etaf = Math.Sqrt(es2 * Math.Cos(Bf) * Math.Cos(Bf));
            var n = (a - b) / (a + b);
            var r1 = (1 + n * n / 4 + n * n * n * n / 64) * Bf;
            var r2 = 3.0 / 2.0 * n * (1 - n * n / 8) * Math.Sin(2 * Bf);
            var r3 = 15.0 / 16.0 * n * n * (1 - n * n / 4) * Math.Sin(4 * Bf);
            var r4 = 35.0 / 48.0 * n * n * n * Math.Sin(6 * Bf);
            var r5 = 315.0 / 512.0 * n * n * n * n * Math.Sin(8 * Bf);
            var Northing = a / (1 + n) * (r1 - r2 + r3 - r4 + r5) * m0 - 0.001 + 4202812 - 4207988.1206046063;
            var ys = Math.Tan(lng) * Math.Cos(Bf) / Vf * (1 + etaf * etaf * lng * lng * Math.Cos(Bf) * Math.Cos(Bf) * (etaf * etaf / 6 + lng * lng / 10));
            ys = Math.Log(ys + Math.Sqrt(ys * ys + 1));
            var Easting = m0 * Math.Pow(a,2) / b * ys + 500000;
            return new double[] { Easting, Northing };
        }
Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • nice work :)

  • great work, thank you!

  • thank you very much !