How to use [AGSMutablePoint offsetByX:xOffset y:yOffset]

1061
2
10-11-2013 12:31 AM
JamesZhang
New Contributor
[AGSMutablePoint offsetByX:xOffset y:yOffset]

The SDK says:
xOffset : The offset along x coordinate.
yOffset : The offset along y coordinate.

What does offset mean exactlly. Does it mean the International Meter Unit.
Now I want to add 1000 meters in y coordinate.  Here is my code, is it correct:

[PHP]
AGSMutablePoint *point = [AGSMutablePoint pointWithX:webMercatorX y:webMercatorY spatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS_1984_WEB_MERCATOR_AUXILIARY_SPHERE]];    //Web Mercator

[point offsetByX:0 y:1000];   //add 1000 meters in y coordinate
[/PHP]

Thank you.
0 Kudos
2 Replies
JamesZhang
New Contributor
In addition.  Create two points by offsetY: 1000

[PHP]
AGSPoint *p1 = [AGSPoint pointWithX:webMercatorX y:webMercatorY spatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS_1984_WEB_MERCATOR_AUXILIARY_SPHERE]];
                   
AGSMutablePoint *p2 = [AGSMutablePoint pointWithX:p1.x y:p1.y spatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS_1984_WEB_MERCATOR_AUXILIARY_SPHERE]];
[p2 offsetByX:0 y:1000];
[/PHP]

Then calculate the distance between p1 and p2:

[PHP]

    float len1 = [p1 distanceToPoint:p2];
   
    AGSMutablePolyline *line = [[AGSMutablePolyline alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS_1984_WEB_MERCATOR_AUXILIARY_SPHERE]];
    [line addPathToPolyline];
    [line addPointToPath:p1];
    [line addPointToPath:p2];
   
    AGSGeometryEngine *engine = [AGSGeometryEngine defaultGeometryEngine];
    float len2 = [engine lengthOfGeometry:line];
    float len3 = [engine geodesicLengthOfGeometry:line inUnit:AGSSRUnitMeter];
    float len4 = [engine shapePreservingLengthOfGeometry:line inUnit:AGSSRUnitMeter];

[/PHP]

The result is:
len1 = len2 = 1000 meters
len3 = len4 = 776.44727 meters

In fact, the real result should be 776.44727 (I measured it in the outdoors, the latitude of my GPS position is 39.082718274606).
So why offsetY:1000 results 776.44727 ? And how can I get the real 1000 meters offset.
0 Kudos
JamesZhang
New Contributor
Finally, I got the relationship between these values:

offset * cos(latitude) = real distance
1000 * cos(DEGREES_TO_RADIANS(39.082718274606)) = 776.236

Yeah~
0 Kudos