Omzetten Lat Lon (srid 4326) naar X Y (srid 31370)

srid 4326 = WGS84
srid 31370 = Belge Lambert 72

Twee klasses aanmaken

        public class RootObject
        {
            public List<Geometry> geometries { get; set; }
        }

        public class RequestRoot
        {
            public string geometryType { get; set; }
            public List<Geometry> geometries { get; set; }
        }

in code

var url = @"http://srvarcgis/arcgis/rest/services/Utilities/Geometry/GeometryServer/project";
NameValueCollection myQueryCollection = new NameValueCollection();
myQueryCollection.Add("inSR", "4326"); <!-- origineel srid -->
myQueryCollection.Add("outSR", "31370"); <!-- nieuw srid -->
myQueryCollection.Add("transformation", "1610"); <!-- volgnummer omzetting -->
myQueryCollection.Add("f", "pjson");
myQueryCollection.Add("transformForward", "false");
// parameter met lat en lon
var reqpar = new RequestRoot();
reqpar.geometries = new List<Geometry>();
var geo = new Geometry();
geo.x = location.Longitude;
geo.y = location.Latitude;
reqpar.geometries.Add(geo);
reqpar.geometryType = "esriGeometrypoint";
myQueryCollection.Add("geometries", Newtonsoft.Json.JsonConvert.SerializeObject(reqpar));
// einde parameter met lat en lon

using (WebClient wc = new WebClient())
{
  wc.QueryString = myQueryCollection;
  var json = wc.DownloadString(url);
  RootObject coor = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(json);
  Console.WriteLine(coor.geometries[0].x);
  Console.WriteLine(coor.geometries[0].y);
}

 

Categories:

Related Article