The function getLength(point1, point2) should calculate distances between two points.
When I am trying to calculate distance between points having 100 meters between them
p1=new esri.geometry.Point(3997030.6690969253, 7444299.320646087, new esri.SpatialReference({ wkid: 102113 }));
Object
p2=new esri.geometry.Point(3996951.455397143, 7444142.154020177, new esri.SpatialReference({ wkid: 102113 }));
Object
esri.geometry.getLength(p1, p2)
176.00045037719127
I am getting 176 which is wrong. Projection is Web Mercator (WKID 102113).
@Krystian found that getLength
uses just Pythagoras theorem to calculate length. So it gives length in projection meters. How to obtain distance in real meters?
Answer
Web Mercator Auxiliary Sphere is WKID 102100
http://resources.arcgis.com/en/help/arcgisonline-content/index.html#//011q00000002000000
var polyline = {
"paths":[[[3997030.6690969253, 7444299.320646087], [3996951.455397143, 7444142.154020177]]],
"spatialReference":{"wkid":102100}
};
console.log(JSON.stringify(polyline));
polyline = new esri.geometry.Polyline(polyline);
console.log(JSON.stringify(polyline));
polyline = esri.geometry.webMercatorToGeographic(polyline);
console.log(JSON.stringify(polyline));
console.log(esri.geometry.geodesicLengths([polyline], esri.Units.METERS));
//output 99.93917832865446
6.1 cm short, good enough for govment work?
No comments:
Post a Comment