Select to view content in your preferred language

Arcade custom symbology

1126
5
Jump to solution
12-08-2023 07:32 AM
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Based on the sample data how can I create a new column/variableA&B, based on when certain conditions are met from two columns using Arcade and then assign colors to the new column's categorical values accordingly?

I am using Pro 3.1.

Sample data:

ID A       B       A&B
1  Present Present A Present & B Present 
2  Absent  Present A Absent  & B Present
3  Present Absent  A Present & B Absent
4  Absent  Absent  A Absent  & B Absent
5  Present Present A Present & B Present 
6  Absent  Present A Absent  & B Present
7  Present Absent  A Present & B Absent
8  Absent  Absent  A Absent  & B Absent

 

Color conditions:

  • If A Present & B Present then color red.
  • If A Absent & B Present or A Present & B Absent then color orange.
  • If A Absent & B Absent then color yellow.
Question | Analyze | Visualize
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

You don't necessarily need to calculate a whole new field for this, but you could. Whether you calculate the field or use this expression directly in the symbology settings, it is the same.

This is simple enough in Arcade. Note, however, that the expression won't directly set the color. Rather, it will return a value that your symbology settings will use for categories. You can call them 'red', 'orange', and 'yellow', but they may as well be 'a', 'b', and 'c' for all the different it makes. Colors are set separately from the expression.

Here are your color conditions in Arcade

 

return when(
  $feature.A == 'Present' && $feature.B == 'Present', 'red',
  ($feature.A == 'Absent' && $feature.B == 'Present') || ($feature.A == 'Present' && $feature.B == 'Absent'), 'orange',
  $feature.A == 'Absent' && $feature.B == 'Absent', 'yellow',
  'other'
)

 

However, you don't really need all this. Since it doesn't matter which value is absent/present, just the count, we can simplify matters.

// this will create a 2-item array of either True or False
var present = [
  $feature.A == 'Present',
  $feature.B == 'Present'
]

return when(
  All(present), 'red',    // matches when both are 'Present'
  Any(present), 'orange', // matches when either are 'Present', but only evaluates if the first check is false; in other words, when only 1 is 'Present'
  'yellow' // logically anything else will be when both are 'Absent', so we don't actually need any conditions
)

 

- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
Ed_
by MVP Regular Contributor
MVP Regular Contributor

@KenBuja happy Friday, hope all is well, when you have the time, can you please have a look into this? Cheers!

Question | Analyze | Visualize
0 Kudos
jcarlson
MVP Esteemed Contributor

You don't necessarily need to calculate a whole new field for this, but you could. Whether you calculate the field or use this expression directly in the symbology settings, it is the same.

This is simple enough in Arcade. Note, however, that the expression won't directly set the color. Rather, it will return a value that your symbology settings will use for categories. You can call them 'red', 'orange', and 'yellow', but they may as well be 'a', 'b', and 'c' for all the different it makes. Colors are set separately from the expression.

Here are your color conditions in Arcade

 

return when(
  $feature.A == 'Present' && $feature.B == 'Present', 'red',
  ($feature.A == 'Absent' && $feature.B == 'Present') || ($feature.A == 'Present' && $feature.B == 'Absent'), 'orange',
  $feature.A == 'Absent' && $feature.B == 'Absent', 'yellow',
  'other'
)

 

However, you don't really need all this. Since it doesn't matter which value is absent/present, just the count, we can simplify matters.

// this will create a 2-item array of either True or False
var present = [
  $feature.A == 'Present',
  $feature.B == 'Present'
]

return when(
  All(present), 'red',    // matches when both are 'Present'
  Any(present), 'orange', // matches when either are 'Present', but only evaluates if the first check is false; in other words, when only 1 is 'Present'
  'yellow' // logically anything else will be when both are 'Absent', so we don't actually need any conditions
)

 

- Josh Carlson
Kendall County GIS
KatClifton
Occasional Contributor

@Ed_ and @jcarlson , hoping I can get some insight from you both on a similar issue.

I have a field named "Status" that has about six or seven values defined by a domain. I would like to categorize these values into a smaller number of values using Arcade and then use those three values for defining the symbology.

When I use the code on a field that does not have a domain applied, I use var reviewStatus = $feature.reviewstatus and it works fine. 

However, when I attempt to use the code below on a field that DOES have domain applied, all items return as Complete. However, I can look in the data and see some values that are Needs Review or Pending.

Here's what I have:

var reviewStatus = DomainName($feature,"reviewstatus")

if (reviewStatus == "")
{
return "Needs Review"
}

if (IsEmpty(reviewStatus))
{
return "Needs Review"
}

if (reviewStatus == "Avoid")
{
return "Needs Review"
}

if (reviewStatus == "High Priority")
{
return "Needs Review"
}

if (reviewStatus == "In Progress")
{
return "Needs Review"
}

if (reviewStatus == "Needs Review")
{
return "Needs Review"
}

if (reviewStatus == "Pending")
{
return "Pending"
}

else
{
return "Complete"
}

0 Kudos
jcarlson
MVP Esteemed Contributor

You need to check the values of the fields based on the domain code, not the domain name. I'm assuming the value "In Progress" might be stored as "in_progress" or something like that? You'd need to check if(reviewStatus == 'in_progress') if that's the case.

To check against the description itself, you need to use DomainName($feature, 'reviewStatus') to pull the text name.

- Josh Carlson
Kendall County GIS
0 Kudos
KatClifton
Occasional Contributor

@jcarlson , thanks for your prompt reply! Just looked at the domain code, and I see that one of the values is truncated.  

So, I will update my Arcade code to refer to the domain code (not the name) and update the Arcade to consider the truncated values in the code field.

Much appreciated!!!

0 Kudos