Get shape_length for newly added lines

3935
2
Jump to solution
02-13-2015 09:11 AM
RiverTaig1
Occasional Contributor

I'm handling a linear feature layer's Edit-complete event and looking at the returned value for the newly created polyline feature.  It seems that in neither the attributes collection nor the geometry collection is the length of the polyline easily obtainable.  I guess I could apply a little Pythagorean theorem and solve it myself, but that seems just a bit crazy. Is there something I'm missing? And also, Is it finally time to admit that Pythagoras was right and call his theorem a law??? I'm voting yes.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
OwenEarley
Occasional Contributor III

The feature layer edit-complete event returns a list of FeatureEditResults. This only has a limited number of properties to indicate if the operation was successful.

To get the length of the new shape you would need to query the feature layer using the objectId property of the new line. You can define which fields to return in the query so you should be able to get the shape length.

View solution in original post

0 Kudos
2 Replies
OwenEarley
Occasional Contributor III

The feature layer edit-complete event returns a list of FeatureEditResults. This only has a limited number of properties to indicate if the operation was successful.

To get the length of the new shape you would need to query the feature layer using the objectId property of the new line. You can define which fields to return in the query so you should be able to get the shape length.

0 Kudos
RiverTaig1
Occasional Contributor

Thank you for the reply Owen; it's too bad that you have to query the feature layer (round-trip to server, right?) just to get the length of the polyline geometry which is obviously visible on the map. To get around this, I wrote the function below.  Thank you Mr. Pythagorus for suggesting this algorithm.

function GetShapeLengthFromPolylineGeometry(polylineGeometry){

    //Assumes that polylineGeometry has a single path

    var firstPath = polylineGeometry.paths[0];

    var totalLength = 0;

    for(var i = 0; i < firstPath.length - 1; i++){

        pointI = firstPath;

        pointIPlusOne = firstPath[i+1];

        sideA = pointI[0] - pointIPlusOne[0]; //delta X

        sideB = pointI[1] - pointIPlusOne[1]; //delta y

        aSquared = sideA * sideA;

        bSquared = sideB * sideB;

        c = Math.sqrt(aSquared + bSquared);

        totalLength +=  c;

    }

    //For me, I need the answer in feet, but the units are in meters

    var answer = totalLength * 3.28084;

    return parseFloat(answer).toFixed(1);

}

0 Kudos