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
Option 4: Unique Symbols, using an Arcade expression
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:
An Arcade expression might not be the best way here.
Going from this:
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.
This will hide all features with null values in the confirmation field, allowing you to use a simple symbology with unique values:
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):
Select each symbol where the confirmation field is null (Ctrl + left click to select multiple), remove those from the symbology:
Uncheck "Show all other values":
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:
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:
Click on the expression button, copy/paste and edit the expression below, apply everything.
// 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:
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
Option 4: Unique Symbols, using an Arcade expression
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:
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.