Find the length of sides of a polygon

10-27-2020 02:02 AM
Occasional Contributor

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

0 Kudos
4 Replies
MVP Legendary Contributor

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. 

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.

Occasional Contributor

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) {
        "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) {

                // debugger; 
0 Kudos
MVP Legendary Contributor

That tells me that you have to run the geometry through the simplify method first then. 

Occasional Contributor

Thank you again, Still did not work . I used the traditional way to find out the length of a line 

0 Kudos