Transform MapPoint to GCS

267
2
07-31-2017 12:39 PM
Highlighted
Regular Contributor

Hi,

I'm converting some code from ArcObjects to ArcPro.  The following bit of code is working.  It converts a point clicked on by the user, to decimal degrees, but I'm sure there is a smoother way to do this.  

var mousePoint = MapView.Active.ClientToMap(e.ClientPoint);

ToGeoCoordinateParameter ddParam = new ToGeoCoordinateParameter(GeoCoordinateType.DD);
string geoString = mousePoint.ToGeoCoordinateString(ddParam);

ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(geoString);

string[] mapPoint = geoString.Split(' ');

mapPoint[0] = mapPoint[0].Remove(mapPoint[0].Length - 1); //the N
mapPoint[1] = "-" + mapPoint[1].Remove(mapPoint[1].Length - 1); //the W; use the '-' to change it from Easting

What would the proper way be to take mousePoint and convert/transform it to DD.

Thanks,

Reply
0 Kudos
2 Replies
Highlighted
Regular Contributor

So I guess I am answering my own question, but by scouring through more of the SDK samples on GitHub, I came up with this:

protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{

double lat;
double lng;

var coord = GeometryEngine.Instance.Project(geometry, SpatialReferences.WGS84) as MapPoint;
if (coord != null)
{
lng = coord.X;
lat = coord.Y;

<more code here..................................>

Previously I was using the HandleMouseDown event, but this event gives me the Geometry of the click, which is exactly what I was looking for.  Then I just have to Project it.  Much simpler than my first attempt.

Hopefully this helps someone else.

Reply
0 Kudos
Highlighted
by Esri Regular Contributor
Esri Regular Contributor

Hi Brian,

 You probably noticed by now that there are some significant differences between ArcObjects and the ArcGIS Pro SDK.  If you are new to the ArcGIS Pro SDK I would recommend to look at some the 'ProConcept' documents we provide on our documentation wiki: https://github.com/Esri/arcgis-pro-sdk/wiki .  Needless to say samples are always helpful (which you already discovered) and so are our ProSnippets which are in essence small copy/paste ready snippets that perform a specific task.  In case you haven't tried this there are quite a few technical sessions on YouTube, you can find them searching for "arcgis pro sdk for .net".   

Reply
0 Kudos