I have an arcade expression for a popup that returns a text string comprised of a land use description and a length. How would I go about summarizing the total length by the land use description?
Solved! Go to Solution.
I think you need to change the decode to be decoding i.USE_CODE, as currently it's decoding the feature object itself? And you need to pass that decoded value into your dictionary not the i.USE_CODE, so something like this:
var buffer = BufferGeodetic($feature, 50, "feet")
var int_ma = Intersects(FeatureSetByName($map, "AllParcels"), BufferGeodetic($feature, 50, "feet"))
var leng = LengthGeodetic($feature, 'feet')
var int_dict = {}
var xs = ""
for (var i in int_ma){
var Ucode = decode(i.USE_CODE,
"0101", "Multiple-Use, Primarily Residential",
"0102", "Multiple-Use, Primarily Residential",
"0104", "Multiple-Use, Primarily Residential",
"031", "Multiple-Use, Primarily Commercial",
"0316", "Multiple-Use, Primarily Commercial",
"0321", "Multiple-Use, Primarily Commercial",
"101", "Residential, Single Family",
"1010", "Residential, Single Family",
"1014", "Residential, Multi-family",
"102", "Residential, Multi-family",
"130", "Residential, Vacant Land",
"300", "Commercial",
"3000", "Commercial",
"302", "Commercial",
"400", "Industrial",
"4000", "Industrial",
"901", "Exempt Property",
"902", "Exempt Property",
'other');
var xs = AreaGeodetic(Intersection(buffer, i), 'square-feet')
if(HasKey(int_dict,UCode)){
int_dict[UCode] += xs
} else {
int_dict[UCode] = xs
}
var total = 0
var out_str = ''
for (var t in int_dict){
total += sum(number(int_dict[t]))
}
for (var d in int_dict){
out_str += '\n' + Ucode + ' - ' +round(number(int_dict[d])/(total)*leng,2)+" Ft"
}}
return out_str
Hi,
I'm a little confused because the screenshot and your code above don't match - I'm guessing the problem is because there are multiple codes linked to one land use description (e.g. '0101' and '0102' for "Multiple-Use, Primarily Residential") so they're not being aggregated? If you use your "decode" before you write the key to the int_dict variable that should group it all correctly (i.e. using "Multiple-Use, Primarily Residental" use the key instead of the code). Otherwise it all looks good to me.
To post code:
Wow, I searched and searched for an error, because your expression returned the correct result (except for that "0" at the start). But you actually have multiple codes for the same land use...
So you need to summarize by the actual land use, not the code. Do the decoding in the loop where you fill int_dict.
Thanks! That makes sense, but I'm having trouble getting that to work. I moved the decode up into the first loop but now everything is returning as "Other". Do I have to change something with the HasKey?
var buffer = BufferGeodetic($feature, 50, "feet")
var int_ma = Intersects(FeatureSetByName($map, "AllParcels"), BufferGeodetic($feature, 50, "feet"))
var leng = LengthGeodetic($feature, 'feet')
var int_dict = {}
var xs = ""
for (var i in int_ma){
var Ucode = decode(i,
"0101", "Multiple-Use, Primarily Residential",
"0102", "Multiple-Use, Primarily Residential",
"0104", "Multiple-Use, Primarily Residential",
"031", "Multiple-Use, Primarily Commercial",
"0316", "Multiple-Use, Primarily Commercial",
"0321", "Multiple-Use, Primarily Commercial",
"101", "Residential, Single Family",
"1010", "Residential, Single Family",
"1014", "Residential, Multi-family",
"102", "Residential, Multi-family",
"130", "Residential, Vacant Land",
"300", "Commercial",
"3000", "Commercial",
"302", "Commercial",
"400", "Industrial",
"4000", "Industrial",
"901", "Exempt Property",
"902", "Exempt Property",
'other');
var xs = AreaGeodetic(Intersection(buffer, i), 'square-feet')
if(HasKey(int_dict,i.USE_CODE)){
int_dict[i.USE_CODE] += xs
} else {
int_dict[i.USE_CODE] = xs
}
var total = 0
var out_str = ''
for (var t in int_dict){
total += sum(number(int_dict[t]))
}
for (var d in int_dict){
out_str += '\n' + Ucode + ' - ' +round(number(int_dict[d])/(total)*leng,2)+" Ft"
}}
return out_str
I think you need to change the decode to be decoding i.USE_CODE, as currently it's decoding the feature object itself? And you need to pass that decoded value into your dictionary not the i.USE_CODE, so something like this:
var buffer = BufferGeodetic($feature, 50, "feet")
var int_ma = Intersects(FeatureSetByName($map, "AllParcels"), BufferGeodetic($feature, 50, "feet"))
var leng = LengthGeodetic($feature, 'feet')
var int_dict = {}
var xs = ""
for (var i in int_ma){
var Ucode = decode(i.USE_CODE,
"0101", "Multiple-Use, Primarily Residential",
"0102", "Multiple-Use, Primarily Residential",
"0104", "Multiple-Use, Primarily Residential",
"031", "Multiple-Use, Primarily Commercial",
"0316", "Multiple-Use, Primarily Commercial",
"0321", "Multiple-Use, Primarily Commercial",
"101", "Residential, Single Family",
"1010", "Residential, Single Family",
"1014", "Residential, Multi-family",
"102", "Residential, Multi-family",
"130", "Residential, Vacant Land",
"300", "Commercial",
"3000", "Commercial",
"302", "Commercial",
"400", "Industrial",
"4000", "Industrial",
"901", "Exempt Property",
"902", "Exempt Property",
'other');
var xs = AreaGeodetic(Intersection(buffer, i), 'square-feet')
if(HasKey(int_dict,UCode)){
int_dict[UCode] += xs
} else {
int_dict[UCode] = xs
}
var total = 0
var out_str = ''
for (var t in int_dict){
total += sum(number(int_dict[t]))
}
for (var d in int_dict){
out_str += '\n' + Ucode + ' - ' +round(number(int_dict[d])/(total)*leng,2)+" Ft"
}}
return out_str
I've tried that and it seems like it's grouping the use types together properly but not applying the use code descriptions correctly. Any ideas?
You're printing out Ucode which is just the most recent decoded value, replace "Ucode" with "d" in the out_str line to print out the relevant dictionary key.
Ah that's it! Thank you so much for your help.
No worries, glad I could help out!