Get Geocode (x, y) from Sketch Layer graphic (point)

707
4
Jump to solution
04-18-2013 12:04 PM
JoshuaPowell1
New Contributor II
Hello all:

We are attempting to get a geocode (i.e., longitude, latitude) from the sketch layer. To date we have been successful in getting the X and Y from the point but they look like this:

89569.25265 45236.32566


This obviously is not even close to being a geocode (i.e., longitude, latitude), at least not in my normal line of thinking.

Now we're using a notification to use respondToGeomChanged [see below]:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToGeomChanged:) name:AGSSketchGraphicsLayerGeometryDidChangeNotification object:nil];


That method, when called, fires, gets the geometry information from the sketchLayer that we've already instantiated.

self.sketchLayer.geometry


If we simply put that in a log, we can find out that it's a mutable point ... and from there we can build that out appropriately:

AGSMutablePoint *currentSketchValue = self.sketchLayer.geometry;


Now that we have an AGSMutablePoint the documentation from Esri for version 10.1 of the SDK we see we have access to an X (double) and a Y (double) ... but these are not longitude and latitude. These are the numbers that I showed above.

How do we either A) get the longitude and latitude or B) convert the AGSMutablePoint X & Y to a longitude and latitude?
0 Kudos
1 Solution

Accepted Solutions
JoshuaPowell1
New Contributor II
I figured out what was going on. It appears that my Feature Layer was set to WGS 4326 and the Sketch Layer defaults to Web Mercator. To resolve this I passed my Sketch Layers geometry information through the AGSGeometryWebMercatorToGeographic utility method and out came the correct geocode (i.e., latitude, longitude.

If you'd like to try this out, I was using the following:

- (void) didOpenWebMap:(AGSWebMap *)webMap intoMapView:(AGSMapView *)mapView {      ...      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToGeomChanged:) name:AGSSketchGraphicsLayerGeometryDidChangeNotification object:nil];      ...  }  - (void)respondToGeomChanged: (NSNotification*) notification {      if([self.sketchLayer.geometry isValid] && ![self.sketchLayer.geometry isEmpty]) {                  AGSGeometry *currentSketchValue2 = (AGSEnvelope*)AGSGeometryWebMercatorToGeographic(self.sketchLayer.geometry);         NSLog(@"AGSGeometryWebMercatorToGeographic: %@", currentSketchValue2);      } }


Cheers!

View solution in original post

0 Kudos
4 Replies
JoshuaPowell1
New Contributor II
Following up with a few details. The information that I'm receiving is a mutable point (i.e., AGSMutablePoint). When displayed in the debugger we get:

AGSMutablePoint:
x = -13628019.829820,
y = 4549121.863850,
spatial reference: [
    AGSSpatialReference: wkid = 102100,
    wkt = null
]


Questions:


  1. Why are those X and Y coordinates not a simple GeoCode (e.g., latitude, longitude)?

  2. More importantly can I just convert those numbers or does something else need to happen?

0 Kudos
JoshuaPowell1
New Contributor II
I figured out what was going on. It appears that my Feature Layer was set to WGS 4326 and the Sketch Layer defaults to Web Mercator. To resolve this I passed my Sketch Layers geometry information through the AGSGeometryWebMercatorToGeographic utility method and out came the correct geocode (i.e., latitude, longitude.

If you'd like to try this out, I was using the following:

- (void) didOpenWebMap:(AGSWebMap *)webMap intoMapView:(AGSMapView *)mapView {      ...      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToGeomChanged:) name:AGSSketchGraphicsLayerGeometryDidChangeNotification object:nil];      ...  }  - (void)respondToGeomChanged: (NSNotification*) notification {      if([self.sketchLayer.geometry isValid] && ![self.sketchLayer.geometry isEmpty]) {                  AGSGeometry *currentSketchValue2 = (AGSEnvelope*)AGSGeometryWebMercatorToGeographic(self.sketchLayer.geometry);         NSLog(@"AGSGeometryWebMercatorToGeographic: %@", currentSketchValue2);      } }


Cheers!
0 Kudos
JoshuaPowell1
New Contributor II
Just to be clear this was the ticket.

AGSGeometry *currentSketchValue2 = (AGSEnvelope*)AGSGeometryWebMercatorToGeographic(self.sketchLayer.geometry);
0 Kudos
JoshuaPowell1
New Contributor II
0 Kudos