Select to view content in your preferred language

A simple arcade question

4823
8
Jump to solution
09-04-2018 06:06 PM
CandiceBardsley1
Occasional Contributor

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...

Tags (1)
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

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";
}‍‍‍‍‍‍‍‍‍‍

View solution in original post

8 Replies
johnmosheim1
Regular Contributor

Is this what you are looking for?

JM

0 Kudos
CandiceBardsley1
Occasional Contributor

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.

0 Kudos
XanderBakker
Esri Esteemed Contributor

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";
}‍‍‍‍‍‍‍‍‍‍
CandiceBardsley1
Occasional Contributor

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?

0 Kudos
XanderBakker
Esri Esteemed Contributor

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);
CandiceBardsley1
Occasional Contributor

Awesome, that is working like a dream. Thanks for the help!

XanderBakker
Esri Esteemed Contributor

You're welcome. Glad it works!

0 Kudos
johnmosheim1
Regular Contributor

Hi Candice, I'm not a wiz but maybe this might do it ("if" expression does not appear to have the right syntax)

John