I am using the ArcGIS .NET SDK
with WPF
, and my code is based on this project.
I am trying to load polygons from a database to display on the Map. I also want to be able to edit these polygons and update them on the database. I got everything working fine, as I was saving my polygons with the SpatialReferences.WebMercator property.
But now I have a database where the polygons are saved as Wgs84 (lat & lon). Now I can load these polygons onto the map, but I am not able to edit them, as the Map is WebMercator and the polygons are Wgs84. As soon as I try to edit I get an exception:
The input spatial reference does not match the owning spatial reference...
I need to convert my polygons as soon as I load them from the database (Wgs84 to WebMercator), and convert them back right before I save to the database (WebMercator to Wgs84).
So I was able to do the first conversion, I load the Wgs84 polygon from the database and convert each point to WebMercator. I can display these polygons and I can also edit them.
But I am struggling to do the second conversion when trying to save a polygon. I did find a formula that can convert these WebMercator points back to Wgs84 to save on the database, but in addition to the lat and lon it also needs a zone. So the way I get the points:
String geomStr = MyMapView.SketchEditor.Geometry.ToJson();
From there I can get all the lat & lon pairs to convert, but I need the zone of each point. Is there any way to retrieve the zone from the Graphic or Geometry object? Or what about figuring out the zone from just knowing the lat or lon point? This is all I need before I can try the conversion formula for Wgs84 to WebMercator.
This tool has the functionality I need. But it is not 100% accurate when converting from EPSG:3857 to EPSG:4326.