Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert geocoordinates in Javascript to geocoordinates in C#

I have got some javascript code and I'd like to convert this to C#. I have no idea of the best way to structure this or if there is an easy way to convert the code.

A sample of this code is shown below.

// ellipse parameters
var e = { WGS84:    { a: 6378137,     b: 6356752.3142, f: 1/298.257223563 },
          Airy1830: { a: 6377563.396, b: 6356256.910,  f: 1/299.3249646   },
          Airy1849: { a: 6377340.189, b: 6356034.447,  f: 1/299.3249646   } };

// helmert transform parameters
var h = { WGS84toOSGB36: { tx: -446.448,  ty:  125.157,   tz: -542.060,   // m
                           rx:   -0.1502, ry:   -0.2470,  rz:   -0.8421,  // sec
                           s:    20.4894 },                               // ppm
          OSGB36toWGS84: { tx:  446.448,  ty: -125.157,   tz:  542.060,
                           rx:    0.1502, ry:    0.2470,  rz:    0.8421,
                           s:   -20.4894 } };


function convertOSGB36toWGS84(p1) {
  var p2 = convert(p1, e.Airy1830, h.OSGB36toWGS84, e.WGS84);
  return p2;
}

The full code can be downloaded from: Javascript Grid Code

EDIT: Thank you all so far for your help; I guess the second requirement is that the reminder of the code in the link can be converted. The focus of the snippet was on the Anonymous Types.

like image 582
Coolcoder Avatar asked Dec 10 '09 15:12

Coolcoder


1 Answers

Your JavaScript snippet is creating anonymous types. You can do the same thing in C#:

var e = new
{
    WGS84 = new { a = 6378137, b = 6356752.3142, f = 1 / 298.257223563 },
    Airy1830 = new { a = 6377563.396, b = 6356256.910, f = 1 / 299.3249646 },
    Airy1849 = new { a = 6377340.189, b = 6356034.447, f = 1 / 299.3249646 }
};

var h = new
{
    WGS84toOSGB36 = new
    {
        tx = -446.448, ty = 125.157, tz = -542.060, // m
        rx = -0.1502, ry = -0.2470, rz = -0.8421,   // sec
        s = 20.4894                                 // ppm
    },                               
    OSGB36toWGS84 = new
    {
        tx = 446.448,
        ty = -125.157,
        tz = 542.060,
        rx = 0.1502,
        ry = 0.2470,
        rz = 0.8421,
        s = -20.4894
    }
};
like image 194
Judah Gabriel Himango Avatar answered Sep 22 '22 03:09

Judah Gabriel Himango