Arcade Symbology

502
6
04-13-2022 07:39 AM
MariyanaKostov1
New Contributor III

I have a text filed that I want to symbolize: if there is no value -a red dot; if there is a value -a green dot.

I started but I'm new to Arcade and I'm stuck:

 var dot=$feature.Name
if dot=null
return "red"

0 Kudos
6 Replies
KenBuja
MVP Esteemed Contributor

You can use IIF

 

iif ($feature.Name != '', 'green', 'red') //if the attribute is a blank string
iif ($feature.Name != null, 'green', 'red') //if the attribute is a null value

 

 

jcarlson
MVP Esteemed Contributor

IsEmpty will check for nulls and empties. I think throwing that into an IIF would be maybe the simplest yet.

Iif(IsEmpty($feature.Name), 'red', 'green')

 

I always forget about just using IIF sometimes!

- Josh Carlson
Kendall County GIS
jcarlson
MVP Esteemed Contributor

In Arcade (as in many other coding languages), a single "=" assigns a value. "dot = null" will assign the dot variable the value null.

Two equals signs checks the value and returns a true or false. "dot == null" -> True/False.

Also, in Arcade, if statements follow the format

if ( condition ) {
do something
} else {
do something
}

The "else" is optional, but in your case, it will help to return a specific value. 

Re-writing your expression to follow that, we would have something like this:

var dot = $feature.Name

if (dot == null){
    return "red"
} else {
    return "green"
}

 

- Josh Carlson
Kendall County GIS
MariyanaKostov1
New Contributor III

Thank you gentlemen! I'll give it a try.

 

0 Kudos
MariyanaKostov1
New Contributor III

This is what I got which is not what I expected:-)

MariyanaKostov1_0-1649861906243.png

 

Some of the dot should be green because there are values in the Name filed.

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Well, the values you get from your expression could be anything, it doesn't necessarily know that you've specified a color name and want the dot to be that color. You still need to go into your symbology classes and define them each.

jcarlson_0-1649862397491.png

 

And, as you found, if you don't have a value present in the data, it won't show up as being available for defining in your symbology settings.

Since your expression is really just a binary output, you can just define the "Other" symbology to be the alternate type. Then, even if the "no value" option shows up sometime in the future, you won't have to go in and re-define the symbology settings.

jcarlson_1-1649862587707.pngjcarlson_2-1649862599043.png

 

- Josh Carlson
Kendall County GIS