Arcade symbology expression for custom groups

347
4
10-30-2019 05:40 AM
Highlighted
New Contributor II

Hello,

Looking to see if someone would be able to assist in generating an Arcade expression that I would like to apply to an internal REST service.

It is a tree inventory layer (800,000+ features) that I would like to create 3 custom groups (High, Medium and Low Risk) based on the tree species name.

Based on these three groups, I want to change the point symbology to either a red colour for high-risk, orange point for medium-risk and yellow colour for low-risk trees. 

I have attempted to do create it but with no luck.  The script below seems to generate only the Low-Risk group when added to arcgis pro.

Script as of now:

var name = $feature.BOTANICAL_NAME


if (name == "Quercus*"|| name == "Acer*"|| name == "Picea*") {

return "High Risk" }
}
if (name == "Betula*" || name =="Fagus*"|| name =="Salix*" || name =="Juglans*" || name =="Gleditsia*" || name =="Malus*" || name =="Prunus*" ) {
return "Medium Risk"}
}

else {

return "Low Risk" }

I never claimed to be good at scripting by the way!

Any assistance would be greatly appreciated!

Josh

4 Replies
Highlighted
MVP Regular Contributor

Hi Josh McMeekin‌,

     I assume your botanical names are like this: "Quercus robur" right? I used split to split the botanical name into a list of characters (words in this case) found between spaces, and then grabbed the first word because indexes start at 0 (the [0]) and then Decode to find the string that you want associated with that word. The last line, 'Low Risk', is the default in case none of the others are found to be a match.

var firstword = Split($feature.name, " ")[0]
return Decode(firstword,
'Quercus','High Risk',
'Acer','High Risk',
'Picea','High Risk',
'Betula','Medium Risk',
'Fagus','Medium Risk',
'Salix','Medium Risk',
'Juglans','Medium Risk',
'Gleditsia','Medium Risk',
'Malus','Medium Risk',
'Prunus', 'Medium Risk',
'Low Risk')

More information:

Decode: Logical Functions | ArcGIS for Developers  

Split: Text Functions | ArcGIS for Developers 

Let me know how that works for you!

Highlighted
New Contributor II

Chelsea!  

Thank you so much for your help with this!  I managed to successfully insert your script into AGOL and get the symbology to set to the 3 categories.  Its perfect!

Greatly apprecaite your help on this one!!

Cheers!

Reply
0 Kudos
Highlighted
New Contributor II

Josh:

FYI... Here's an alternative solution with Python3 using regular expressions.  Though the answer given by Chelsea Rozek is the best way to implement this using Arcade. The only real difference between the two is that if any of the names were not spaced properly then the Arcade solution would not catch it, since the Split function is looking for a space in the field value.  For example if "Juglans nigra" was missing the space, such as "Juglansnigra".  The solution using Python regular expressions would still correctly categorize this.  But, assuming your data is clean and properly spaced, this is a non-issue.  Additionally, you could alter the Regular Expression to catch all cases (upper and lower) of Juglans in the field values.

SOLUTION:

OUTPUT:

Highlighted
New Contributor II

Thank you Jon for your suggestion. I appreciate you sending the pic of your python script as I will be sure to reference this down the road.

I needed the script in Arcade though as I was doing some custom symbology on a web service that I wanted to use in Arc Enterprise.

Thank you again though for your suggestions!

Take care!

Reply
0 Kudos