Select to view content in your preferred language

Symbolising using Arcade based on the values of 2 attributes, Arcade

484
2
Jump to solution
06-14-2022 06:53 PM
Labels (3)
CourtneyWatson
New Contributor III

Hi there, very new to the world of Arcade and i'm failing miserably it seems.  What I am trying to do is create 3 symbology levels 'Severe Danger', 'Medium Risk' and 'Low' based on 2 attribute fields.  riskrangehuman and riskrangeproperty that are updated offline and I want the symbology of the points to change based on the information entered,

If the value in riskrangehuman is 3 or 2 AND the value in riskrangeproperty is 3 I want it to be categorised as 'Severe Danger'

If the value in riskrangehuman is 2 AND the value in riskrangeproperty is 3, I want it to be categorised as 'Medium Danger'

For everything else I want it to be symbolised as 'Low Risk'

 

 

When($feature.riskrangehuman == '3' || $feature.riskrangehuman == '2') && ($feature.riskrangeproperty == '3'), 'Severe Danger'
($feature.riskrangehuman == '2') && ($feature.riskrangeproperty == '3' || $feature.riskrangeproperty == '2'), 'Medium Risk',

'Low risk' )

 

 

 

I get an error saying "Parse Error:Line 4: Unexpected token )"

Any help would be really appreciated

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Welcome to the world of Arcade! Here's what I can see:

  1. You're missing a parenthesis. The function When should have all its parameters inside a single set of ( ), but your first condition is followed by a ")". This effectively closes the Where function.
  2. You're missing a comma after "Severe Danger"
  3. You could use another line break and some indentations, it helps keep things clear and comprehensible.
  4. Similarly, attributes that are going to be used more than once (and are quite long) can be assigned to shorter variables. This keeps your code from getting too wide.
  5. When you're checking if something is equal to multiple values, you could also make use of the function Includes.

As far as the conditions themselves, however, your expression doesn't quite match up with your text. For both "Severe" and "Medium", riskrangeproperty, according to your post, should equal 3. And "Severe" has a riskrangehuman of 2 OR 3, but "Medium" has it as a 2. By that logic, any feature that meets the "Medium" criteria will also meet the "Severe" criteria.

Then again, your expression seems to have 2 OR 3 for riskrangeproperty in the "Medium" condition. So it's not totally clear which is the intended approach. I'll just assume the expression is the one to follow.

Here's your expression, with those suggestions implemented:

var rrh = $feature.riskrangehuman
var rrp = $feature.riskrangeproperty

When(
    Includes(['2', '3'], rrh) && rrp == '3', 'Severe Danger',
    rrh == '2' && Includes(['2', '3'], rrp), 'Medium Risk',
    'Low risk'
)

The comma and parenthesis are definite must-fix items, but the rest are more personal preference. See what works for you!

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

Welcome to the world of Arcade! Here's what I can see:

  1. You're missing a parenthesis. The function When should have all its parameters inside a single set of ( ), but your first condition is followed by a ")". This effectively closes the Where function.
  2. You're missing a comma after "Severe Danger"
  3. You could use another line break and some indentations, it helps keep things clear and comprehensible.
  4. Similarly, attributes that are going to be used more than once (and are quite long) can be assigned to shorter variables. This keeps your code from getting too wide.
  5. When you're checking if something is equal to multiple values, you could also make use of the function Includes.

As far as the conditions themselves, however, your expression doesn't quite match up with your text. For both "Severe" and "Medium", riskrangeproperty, according to your post, should equal 3. And "Severe" has a riskrangehuman of 2 OR 3, but "Medium" has it as a 2. By that logic, any feature that meets the "Medium" criteria will also meet the "Severe" criteria.

Then again, your expression seems to have 2 OR 3 for riskrangeproperty in the "Medium" condition. So it's not totally clear which is the intended approach. I'll just assume the expression is the one to follow.

Here's your expression, with those suggestions implemented:

var rrh = $feature.riskrangehuman
var rrp = $feature.riskrangeproperty

When(
    Includes(['2', '3'], rrh) && rrp == '3', 'Severe Danger',
    rrh == '2' && Includes(['2', '3'], rrp), 'Medium Risk',
    'Low risk'
)

The comma and parenthesis are definite must-fix items, but the rest are more personal preference. See what works for you!

- Josh Carlson
Kendall County GIS
CourtneyWatson
New Contributor III

Perfect, thank you so much!

0 Kudos