Hi - I am new to arcade so need to ask a very simple question...
Is there an 'and' function?
I want to show a warning symbol if a threshold (1951) is met. Each of the objects in the feature class has a different threshold hence I want to isolate each object, then set a value for it.
I've tried the expression below but 'and' mustn't be an option.
If ($feature.OBJECTID=9) and ($feature["PI_Value"] >1951)
{return "warning"} else {return "ok"}
Any help would be greatly appreciated...
Solved! Go to Solution.
Depending on the number of features and different thresholds you have you could have a dictionary that stores the thresholds per ObjectID and you check the PI value against that threshold:
var thresholds = {"9": 1951, "10": 1749, "11": 2103};
var oid = Text($feature.OBJECTID);
var pi_value = $feature["PI_Value"];
if (pi_value > thresholds[oid]) {
return "warning";
} else {
return "ok";
}
However, it is better to have a threshold stored at feature level (in a field) and compare against it:
var threshold = $feature["Threshold"];
var pi_value = $feature["PI_Value"];
if (pi_value > threshold) {
return "warning";
} else {
return "ok";
}
Concerning the error you obtained, you need to use the double equal to compare value (single equal sign is an assignment):
If (($feature.OBJECTID==9) && ($feature["PI_Value"] >1951)) {
return "warning";
} else {
return "ok";
}
Is this what you are looking for?
JM
Hi John
I’ve tried this:
If ($feature.OBJECTID=9) && ($feature["PI_Value"] >1951)
{return "warning"} else {return "ok"}
But get a parse error: unexpected token &&
So I must still be doing something wrong.
Depending on the number of features and different thresholds you have you could have a dictionary that stores the thresholds per ObjectID and you check the PI value against that threshold:
var thresholds = {"9": 1951, "10": 1749, "11": 2103};
var oid = Text($feature.OBJECTID);
var pi_value = $feature["PI_Value"];
if (pi_value > thresholds[oid]) {
return "warning";
} else {
return "ok";
}
However, it is better to have a threshold stored at feature level (in a field) and compare against it:
var threshold = $feature["Threshold"];
var pi_value = $feature["PI_Value"];
if (pi_value > threshold) {
return "warning";
} else {
return "ok";
}
Concerning the error you obtained, you need to use the double equal to compare value (single equal sign is an assignment):
If (($feature.OBJECTID==9) && ($feature["PI_Value"] >1951)) {
return "warning";
} else {
return "ok";
}
Thanks Xander, the double == solved my problem. Regarding the second option of having the threshold stored at feature level, I didn't do this because in the case of this feature class, some of the thresholds are actually when the pi_value is lower than the threshold number, so your script wouldn't work in this instance.
Your first option of using a dictionary has taken what I originally asked for to the next level and is perfect for what I am after. For some reason though when I enter the script like you've written it I get Execution Error:Field not Found...
Is there something missing or do I need to have a threshold entered for every object ID for this to work?
Let's answer this in parts:
Regarding the second option of having the threshold stored at feature level, I didn't do this because in the case of this feature class, some of the thresholds are actually when the pi_value is lower than the threshold number, so your script wouldn't work in this instance.
I think the whole idea of testing a value against a threshold is to determine if the value is low or higher and should yield in either "ok" or "warning". So this should work (in theory).
Your first option of using a dictionary has taken what I originally asked for to the next level and is perfect for what I am after. For some reason though when I enter the script like you've written it I get Execution Error:Field not Found...
Is there something missing or do I need to have a threshold entered for every object ID for this to work?
This error is likely to occur when you are trying to retrieve the threshold value for a certain ObjectID which is not included in the dictionary. Not sure if this should yield the "Execution Error:Field not Found" error.
To avoid this you could use the following code:
function TestThreshold(thresholds, oid, pi_value) {
var result = "oid not found"
for (var key in thresholds) {
if (key == oid) {
var threshold = thresholds[key];
if (pi_value > threshold) {
result = "warning";
} else {
result = "ok";
}
}
}
return result;
}
var thresholds = {"9": 1951, "10": 1749, "11": 2103};
var oid = Text($feature.OBJECTID);
var pi_value = $feature["PI_Value"];
return TestThreshold(thresholds, oid, pi_value);
Awesome, that is working like a dream. Thanks for the help!
You're welcome. Glad it works!
Hi Candice, I'm not a wiz but maybe this might do it ("if" expression does not appear to have the right syntax)
John