I am trying to create an Arcade expression to calculate a field in ArcGIS Pro. In my streets feature there are 4 number fields to evaluate. I can easily use the Min() function to do this. The problem that I am having is sometimes there is a 0 in one or more fields. I need the lowest number that is not a 0. In python I had this script which worked well:
min([x for x in ( !L_F_ADD!, !L_T_ADD!, !R_F_ADD!, !R_T_ADD!) if x is not 0])
I have tried redoing this in Arcade but can't figure it out. Any ideas?
Solved! Go to Solution.
Hi spsummers ,
You are probably not going to like it, but those powerful python list comprehensions are not available in arcade. Can you try this?
var minv = 99999;
var arr =[$feature[L_F_ADD], $feature[L_T_ADD], $feature[L_F_ADD], $feature[L_T_ADD]];
for (var i in arr) {
var v = arr[i];
if (v!=0 && !IsEmpty(v)) {
if (v < minv) {
minv = v;
}
}
}
if (minv == 99999) {
return null;
} else {
return minv;
}
Hi spsummers ,
You are probably not going to like it, but those powerful python list comprehensions are not available in arcade. Can you try this?
var minv = 99999;
var arr =[$feature[L_F_ADD], $feature[L_T_ADD], $feature[L_F_ADD], $feature[L_T_ADD]];
for (var i in arr) {
var v = arr[i];
if (v!=0 && !IsEmpty(v)) {
if (v < minv) {
minv = v;
}
}
}
if (minv == 99999) {
return null;
} else {
return minv;
}
Thank you! Your code worked. I also asked this question on another forum (Geographic Information Systems Stack Exchange ) The solution presented by Hornbydd is this:
var inArray = [$feature.FromAddr_L,$feature.ToAddr_L,$feature.FromAddr_R,$feature.ToAddr_R];
var sortedArray;
sortedArray = sort(inArray);
for(var i in sortedArray)
{
if (sortedArray > 0) break;
}
return sortedArray;
Both solutions work in the Field Calculator. It will be interesting to see if they work in the Attribute Rules.
Thank you!
Hi spsummers ,
That is correct, I thought about this too, but I didn't know if you had any negative values to consider. Thanks for sharing.