Converting from WebMercator to Wgs84

669
1
02-13-2020 08:05 AM
Labels (1)
DanieBester
New Contributor II

I have a set of points (drawn polygon) that have the SpatialReferences.WebMercator property. I need to convert these points to SpatialReferences.Wgs84 before saving to a database. Ideally I would just keep the WebMercator setting, but the existing database is using the Wgs84 format.

I am using the GeometryEngine class, but I noticed that once I reload the polygon, it is off by some way. It is in a different location. How can I make sure this conversion is accurate?

public double[] ConvertMercatorToWgs(double lat, double lon)
{

      MapPoint point = new MapPoint(lon, lat, SpatialReferences.WebMercator);

      

      //These lines did not influence the results

      //GeographicTransformationStep geoStep = new GeographicTransformationStep(108211);
      //GeographicTransformation geoTransform = new GeographicTransformation(geoStep);

      MapPoint convertedPoint = (MapPoint)GeometryEngine.Project(point, SpatialReferences.Wgs84,);

      return new double[] { convertedPoint.X, convertedPoint.Y };

}

0 Kudos
1 Reply
DanieBester
New Contributor II

So as an example, I just drew a polygon with points

-33.9360095288856 18,391141081041, -33,9075206517435 18,390454436898, -33,9303125156119 18,423413355855

After performing the conversion, the points became

-36.1141869553583 18.0832273300021, -36.0798547481093 18.0825746003061, -36.1073205139085 18.113902885547 

0 Kudos