Hi, I'm trying to calculate the areas and lengths of intersecting layers within a selected polygon. I found a really helpful script here: Solved: Popup calculations with Arcade - Esri Community. It has gotten me to 90% to where I need to be. The problem is that this arcade script doesn't like blank or null values. I believe HasKey is the culprit. I need these "blank" values calculated in the popup (and renamed if possible). Is there a solution or workaround? maybe incorporating DefautValue or IsEmpty somehow?
Thank you
var managementareas = FeatureSetByName($map,"ManagmentAreas"); var int_ma = Intersects($feature, managementareas) var int_dict = {} var xs = 0 for (var i in int_ma){ var xs = AreaGeodetic(Intersection($feature, i), 'acres') if(HasKey(int_dict,i.Name)){ int_dict[i.NAME] += xs } else { int_dict[i.NAME] = xs } var out_str = 'Management Area Acreage: '; for (var d in int_dict){ out_str += '\n' + d + '\t|\t' + Text(int_dict[d], '#,###.#') }} return out_str
Solved! Go to Solution.
Create a key that uses a substitute string if i.NAME is blank (line 9) and use that key for the dictionary (lines 10, 11, and 13). Note that I moved the calculation of out_str outside the for loop. It doesn't need to be calculated for each item in the intersected FeatureSet.
var managementareas = FeatureSetByName($map, "ManagmentAreas");
var int_ma = Intersects($feature, managementareas);
var int_dict = {};
var xs = 0;
for (var i in int_ma) {
var xs = AreaGeodetic(Intersection($feature, i), "acres");
var key = iif(IsEmpty(i.NAME), "Empty", i.NAME);
if (HasKey(int_dict, key)) {
int_dict[key] += xs;
} else {
int_dict[key] = xs;
}
}
var out_str = "Management Area Acreage: ";
for (var d in int_dict) {
out_str += "\n" + d + "\t|\t" + Text(int_dict[d], "#,###.#");
}
return out_str;
Create a key that uses a substitute string if i.NAME is blank (line 9) and use that key for the dictionary (lines 10, 11, and 13). Note that I moved the calculation of out_str outside the for loop. It doesn't need to be calculated for each item in the intersected FeatureSet.
var managementareas = FeatureSetByName($map, "ManagmentAreas");
var int_ma = Intersects($feature, managementareas);
var int_dict = {};
var xs = 0;
for (var i in int_ma) {
var xs = AreaGeodetic(Intersection($feature, i), "acres");
var key = iif(IsEmpty(i.NAME), "Empty", i.NAME);
if (HasKey(int_dict, key)) {
int_dict[key] += xs;
} else {
int_dict[key] = xs;
}
}
var out_str = "Management Area Acreage: ";
for (var d in int_dict) {
out_str += "\n" + d + "\t|\t" + Text(int_dict[d], "#,###.#");
}
return out_str;
Amazing! this did the trick