AnsweredAssumed Answered

geodesicArea() behavior - different results depending on selection method

Question asked by MollyKFoley on Sep 10, 2018

I have an interactive map that gives users two different levels of selection - when they draw a polygon around features to be selected, it selects the features. If they wish to select from that selection, they may also do that by clicking the table record that corresponds with the feature they want to select. I then have a button that allows them to calculate the acreage where they can choose to either calculate the acreage of ALL selected features (yellow + blue), or calculate the acreage of the subset of selected features (only blue) they chose from the original set of selected features. Illustrated in pictures:

 

Selected features:

 

Selection from selected features (blue):

 

 

-----------------------------------------------------------------------------------

If I calculate the area of all the selected features, I get this:

678.80 acres

Individual areas:

big rectangle: 530.9037711457356

small rectangle: 147.89805635451594

 

If I calculate the area of subset selection (which is the same as the selection in this case), I get this:

678.91 acres

Individual areas:

big rectangle: 530.9380000627551

small rectangle: 147.9687970267487

 

The total for the blue selection is the more accurate number when I compare to numbers in ArcMap. I'm not understanding how different graphic sets for the exact same area can have different acreages. It's as if the way the selection is derived somehow messes with the area of the graphics. For the yellow selection, the feature collection to have the acreage calculated for is derived from the getSelectedFeatures() method. For the blue selection, the feature collection to have the acreage calculated for is derived from grabbing the graphics from the map. Notice, they both are entered into the addAcreage function and carry out the exact same code to perform the acreage summation so the difference occurs before it hits this function.

 

Code:

//Calculate total acreage of selected or highlighted features
function totalAcreage(chosenFeatures) {
    //Figure out which layer needs to have acreage calculated by testing what feature layer
    //comes back with selected features

    //YELLOW SELECTION
    if (chosenFeatures == "selected") {
        var resultFeatures = patchesFL.getSelectedFeatures();
        if (resultFeatures.length > 0) {
            var total = addAcreage(resultFeatures);
        }
        else {
            resultFeatures = hbMgmtTractFL.getSelectedFeatures();
            if (resultFeatures.length > 0) {
                var total = addAcreage(resultFeatures);
            }
            else {
                var total = "No features selected";
            }
        }
    }
    //BLUE SELECTION
    else if (chosenFeatures == "highlighted") {
        var highlightedFeats = map.graphics.graphics;
        if (highlightedFeats.length > 0 && highlightedFeats[0].attributes != undefined) {
            var total = addAcreage(highlightedFeats);
        }
        else {
            var total = "No features highlighted";
        }
    }
    //Clear the dialog box of any previous calculations
    $("#calcAcre-complete-dialog").empty();
    //Add new calculation to dialog box and open it
    domConstruct.place("<p>" + total + "</p>", "calcAcre-complete-dialog");
    $("#calcAcre-complete-dialog").dialog("open");
}

//Sum acreage of selected or highlighted features
function addAcreage(featureList) {
    var acres = 0;
    var total = '';
    for (var i = 0, idxLen = featureList.length; i < idxLen; i++) {
        var areaAcres = geometryEngine.geodesicArea(featureList[i].geometry, "acres");
        console.log(areaAcres);
        acres = acres + areaAcres;
        //Round to two decimal places, return string
        total = parseFloat(acres).toFixed(2) + " acres";
    }
    return total;
}

Outcomes