Arcade custom symbology

604
2
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

2 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