Hi.
I am new to Arcade Expressions and I am having some difficulties understanding how this actually works.
I have a road layer with multiple fields, the ones that I am interested in using for symbology are road type and another confirmation field that has only "yes" as a value.
I would like an expression that can show all the road types but only for the features that have "yes" as a value in the other field.
Can someone explain to me how I can build this expression?
Many thanks.
Solved! Go to Solution.
Ah, sorry, I assumed for ArcGIS Pro.
If you're publishing from Pro, you can try the options above and see if they translate to AGOL/Portal.
If you're doing all your work in AGOL or don't want to publish a new layer:
You can still go with option 1
JohannesLindner_1-1673359310788.png
Option 4: Unique Symbols, using an Arcade expression
JohannesLindner_2-1673359479487.png
if($feature.ConfirmationField != "Yes") {
return "hidden"
}
return $feature.RoadType
Then symbolize by unique symbols, drag and drop the "hidden" legend item into the "Other" category, and uncheck that:
JohannesLindner_3-1673359827162.png
An Arcade expression might not be the best way here.
Going from this:
JohannesLindner_10-1673341498565.png
Option 1: Definition query
Go into the layer options, switch to the Definition Query tab. Click on "New definition query" and use the UI to only select the features where the confirmation field ("TextField2" in my case) is not null. Alternatively, only select where the confirmation field is equal to "Yes". Apply.
JohannesLindner_0-1673339984378.png
This will hide all features with null values in the confirmation field, allowing you to use a simple symbology with unique values:
JohannesLindner_2-1673340136907.png
Option 2: Unique values with multiple fields
In the symbology tab, select both the road type field and the confirmation field ("TextField1" and "TextField2" in my case):
JohannesLindner_3-1673340293710.png
Select each symbol where the confirmation field is null (Ctrl + left click to select multiple), remove those from the symbology:
JohannesLindner_4-1673340429528.png
Uncheck "Show all other values":
JohannesLindner_5-1673340511494.png
This will hide all features with null values in the confirmation field. BUT, while option 1 doesn't include those features in the layer, option 2 does, it only does not draw them. You can still see them in the attribute table, and they are still getting labeled:
JohannesLindner_6-1673340709399.png
Option 3: Arcade expression
Sure, you can do this.
Change to "Single Symbol", format the symbol. Allow symbol property connections and click on the button next to the color picker:
JohannesLindner_7-1673340940700.png
Click on the expression button, copy/paste and edit the expression below, apply everything.
JohannesLindner_8-1673341334953.png
// hide unconfirmed features by giving them a fully transparent color
if($feature.TextField2 != "Yes") {
return "rgba(0, 0, 0, 0)"
}
// define a mapping of road type to color
var mapping = {
"Highway": "red",
"Two-Lane-Road": "rgb(0, 255, 255)"
}
// return the color corresponding to the feature's road type
return mapping[$feature.TextField]
As with option 2, this will include the unconfirmed features in the layer, but will not draw them:
JohannesLindner_9-1673341408951.png
Hi Johannes,
Thank you for taking the time to explain these 3 options.
One thing I forgot to mention is that I want to do this symbology into a web map, so I can share it with my colleagues. I guess the third solution with the Arcade Expression works the same in the web version as in ArcGIS PRO.
Thanks a lot!
Ah, sorry, I assumed for ArcGIS Pro.
If you're publishing from Pro, you can try the options above and see if they translate to AGOL/Portal.
If you're doing all your work in AGOL or don't want to publish a new layer:
You can still go with option 1
JohannesLindner_1-1673359310788.png
Option 4: Unique Symbols, using an Arcade expression
JohannesLindner_2-1673359479487.png
if($feature.ConfirmationField != "Yes") {
return "hidden"
}
return $feature.RoadType
Then symbolize by unique symbols, drag and drop the "hidden" legend item into the "Other" category, and uncheck that:
JohannesLindner_3-1673359827162.png
Hi Johannes,
Thank you so much, this work perfectly.
For option 3, I don't have a button next to the color picker. What version of pro are you using? I currently have 2.9
This was probably 2.8 or 2.9
Make sure you allow symbol property connections (top right of the image under option 3.