Hi All Greetings
How can I find the length of sides of a polygon ( Not Perimeter of the polygon). Is the following right approach or is there any simpler approach please ?
1. find the number of rings in the polygon
2. loop through them
3. calculate length from the start point to end point
Thank you
Almost. Each ring represents its own closed polygon, not a side of a polygon. So once you have the ring (by looping through the rings) you then get the rings points
Each ring is made up of three or more points.
You can use the getPoint method of the polygon class to get the specific point.
https://developers.arcgis.com/javascript/3/jsapi/polygon-amd.html#getpoint
Then make a new Polyline from two points (i.e ring 0 point 0 and point 1) and use that new polyline in the geodesic or planar length method.
Thanks. This is what I think I am doing. But keep getting error : "The operation cannot be performed on a non-simple geometry."
function graphicDimension(resultGraphic) {
require(["esri/geometry/Polyline",
"esri/tasks/support/LengthsParameters", "esri/tasks/GeometryService", "esri/geometry/Point"],
function (Polyline, LengthsParameters, GeometryService, Point) {
for (i = 0; i < resultGraphic.geometry.rings.length; i++) { // value 1 polygon
for (j = 0; j < resultGraphic.geometry.rings[i].length; j++) { //value 6 points
fromPoint = new Point (resultGraphic.geometry.rings[i][j]);
toPoint = new Point( resultGraphic.geometry.rings[i][j + 1]);
//console.log(fromPoint, toPoint);
paths = [
[fromPoint.x, fromPoint.y],
[toPoint.x, toPoint.y]
]
polyLine = new Polyline({
paths: [paths],
spatialReference: app.view.spatialReference
});
lengthParams = new LengthsParameters();
lengthParams.calculationType = "geodesic";
lengthParams.geodesic = true;
lengthParams.polylines = [polyLine];
lengthParams.lengthUnit = "METER";
geomSerVice = new GeometryService(geometryServiceUrl);
geomSerVice.lengths(lengthParams, function (result) {
console.log(result.lengths[0]);
alert("length");
});
// debugger;
}
}
});
};
That tells me that you have to run the geometry through the simplify method first then.
https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#simplify
Thank you again, Still did not work . I used the traditional way to find out the length of a line
√((x_2-x_1)²+(y_2-y_1)²)