Select to view content in your preferred language

Updating attribute value based on other attributes and threshold value

126
1
03-18-2025 11:13 AM
Labels (1)
JaquelineBoog
New Contributor

I am trying to create a map wie Map Viewer Classic where people can add points with soil measurement data. Let's say they can measure the values for lead, copper and cadmium. At the same time there are three threshold values which classify pollution of the soil. These are guideline value, test value and clean up value. So depending on whether one of the measured values reaches one of the threshold values the attribute "soil classification" gets the value 0 for "none of the thresholds reached", 1 for "guideline value reached", 2 for "test value reached" and 3 for "clean up value reached". If one of the measured elements reaches the test value the script can move on to the next row because it's the highest value possible. 

The table of the feature service should then look something like this (there are other attributes as well such as soil type, date of measurement etc. but I will not list them here since they are not important for the calculation): 

leadcoppercadmiumsoil classification
0.51032
0.210.50


I tried to implement this by setting up an Arcade Expression with the form builder: 

var thresholds = {
    "cleanup": {"lead": 1000, "cadmium": 20, "copper": 1000},
    "test": {"lead": 200, "cadmium": 2, "copper": 150},
    "guideline": {"lead": 50, "cadmium": 0.8, "copper": 40}
};

var soilclass = 0
var attributes = ["sm_pb", "sm_cd", "sm_cu"];
Expects($feature, "sm_pb", "sm_cd", "sm_cu");

for (var i = 0; i < Count(attributes); i++) {
    var attribute = attributes[i];
    Console(attribute);

    if(!HasValue( $feature , attribute )){
        continue;
    }

    var value = $feature[attribute]; 
    if (IsEmpty(value)) {
        continue; 
    }

    if(HasValue( thresholds["cleanup"] , attribute )){
        if (value >= thresholds["cleanup"][attribute]) {
            soilclass = 3;
            break;  
        }
    }

    if(HasValue( thresholds["test"] , attribute )){
        if (value >= thresholds["test"][attribute] && soilclass != 3) {
            soilclass = 2;
        }
    }

    if(HasValue( thresholds["guideline"] , attribute )){
        if (value >= thresholds["guideline"][attribute] && soilclass != 2) {
            soilclass = 1;
        }
    }
}

if(soilclass != 0){
    return soilclass ;
} else {
return 0

}


Unfortunately this does not work. I do not get an error message but the correct soilclass does not get calculated if add a point to the map with measurement values. I have spent hours trying to fix this but since debugging is not an easy task within form builder and I am at my wits' end. What am I missing? Help would be greatly appreciated.

0 Kudos
1 Reply
JaquelineBoog
New Contributor

Need to add that I made an error when writing the code down. Line 8 and 9 are supposed to be:

var attributes = ["lead", "cadmium", "copper"];
Expects($feature, "lead", "cadmium", "copper");
0 Kudos