Using geometryEngine projectGeometry results in strange results

2492
3
Jump to solution
05-12-2013 05:27 PM
ChristopheFondacci
New Contributor II
Hi,

I looked in the other threads and cannot find anything about this problem. Maybe it's my misunderstanding of the way to project a point.

I need to convert device's latitude and longitude to my map which is in a 3163 spatial reference.

I do the following :

  • Get the current location from SDK's CoreLocation framework

  • When I need to plot a point on current location, I initialize the current lat/long as an AGSPoint with a WGS84 spatial reference.

  • Then I project it to the spatial reference 3163 and I add this point to one of my graphic layer

This results in the point being misplaced all the time. I first tried the following :
   _defaultSpatialRef = [AGSSpatialReference spatialReferenceWithWKID:3163];      AGSGeometryEngine *engine = [AGSGeometryEngine defaultGeometryEngine];     AGSPoint *point = [AGSPoint pointWithX:currentLocation.coordinate.latitude y:currentLocation.coordinate.longitude spatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS84]];     AGSPoint *projectedPoint= (AGSPoint*)[engine projectGeometry:point toSpatialReference:_defaultSpatialRef];


This sample code always result in returning "nan" information in the resulting AGSpoint x and y coordinates. Because I was not sure how to map X and Y as latitude and longitude I tried to switch lat / long so that X is mapped to longitude and Y mapped to latitude in my origin WGS84 point.

This time, I get results but the resulting point seems to be outside my map's bounds.

Here are my information :


  • location latitude = -22.2682

  • location longitude = 166.442

First try when mapping X with latitude and Y with longitude in my initial point that I project => nan / nan as resulting projected AGSPoint X and Y

Second try when mapping X with longitude and Y with latitude :

  • projected point X = 445586.569662

  • projected point Y = 214879.873427

I think my X should be negative but not sure.
Here are my questions :
- Which way should I map X/Y to lat/long (in all other examples I saw X->lat and Y->lng but it does not give any result)
- Am I doing it the right way or missing anything ?

Thank you very much for your time and answers.
Christophe.
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
- Which way should I map X/Y to lat/long (in all other examples I saw X->lat and Y->lng but it does not give any result)


X = Longitude and Y = Latitude.

- Am I doing it the right way or missing anything?


You are doing it right. I projected point and got slight difference in the result point but it looks correct.

AGSPoint *p = [AGSPoint pointWithX:166.442 y:-22.2682 spatialReference:[AGSSpatialReference wgs84SpatialReference]];
AGSGeometry *pg = [[AGSGeometryEngine defaultGeometryEngine] projectGeometry:p toSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:3163]];
NSLog(@"%@",pg);
//AGSMutablePoint: x = 445554.767830, y = 214880.208082, spatial reference: [AGSSpatialReference: wkid = 3163, wkt = null]

Now, look into why you are getting point out of map's bounds.

What is your map's spatial reference?
Are you creating a graphic with projected point and adding to graphics layer to visualize it?

Regards,
Nimesh

View solution in original post

0 Kudos
3 Replies
NimeshJarecha
Esri Regular Contributor
- Which way should I map X/Y to lat/long (in all other examples I saw X->lat and Y->lng but it does not give any result)


X = Longitude and Y = Latitude.

- Am I doing it the right way or missing anything?


You are doing it right. I projected point and got slight difference in the result point but it looks correct.

AGSPoint *p = [AGSPoint pointWithX:166.442 y:-22.2682 spatialReference:[AGSSpatialReference wgs84SpatialReference]];
AGSGeometry *pg = [[AGSGeometryEngine defaultGeometryEngine] projectGeometry:p toSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:3163]];
NSLog(@"%@",pg);
//AGSMutablePoint: x = 445554.767830, y = 214880.208082, spatial reference: [AGSSpatialReference: wkid = 3163, wkt = null]

Now, look into why you are getting point out of map's bounds.

What is your map's spatial reference?
Are you creating a graphic with projected point and adding to graphics layer to visualize it?

Regards,
Nimesh
0 Kudos
DavidMorrison1
New Contributor
try this:

  _defaultSpatialRef = [AGSSpatialReference spatialReferenceWithWKID:3163];

    AGSGeometryEngine *engine = [AGSGeometryEngine defaultGeometryEngine];
    AGSPoint *point = [AGSPoint pointWithX:currentLocation.coordinate.latitude y:currentLocation.coordinate.longitude spatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS84]];
    AGSPoint *pointProjectedToWGS84 = (AGSPoint *)[engine projectGeometry:point toSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS84]];
    AGSPoint *projectedPoint= (AGSPoint*)[engine projectGeometry:pointProjectedToWGS84 toSpatialReference:_defaultSpatialRef];


i don't really know why but i encountered this problem too and had to project the point to WGS84 before i can project it to my desired spatial reference.
0 Kudos
ChristopheFondacci
New Contributor II
Hi,

Sorry, actually the first code I posted seems to work now.
I think I was manipulating the coordinates with incorrect datatypes, so my coordinates were truncated before being plotted on my map.

Everything works great now.
Christophe.
0 Kudos