Set line colour based off of attribute values using arcade in ArcGIS Online

2062
8
Jump to solution
01-05-2023 10:26 PM
Labels (3)
Keiran_Bray
New Contributor II

Evening all,

I'm currently working on a project where I need to symbolize a footpath polyline based off of two values,

The first value is used to set the symbol type using unique values i.e. paved, sealed, concrete etc

The second value is used to set the colour based off of footpath condition values ranging from 0-5 with specific breaks according to certain condition values i.e 0-0.99, 1-1.99....,

So far I have been able to achieve this within ArcGIS Pro using attribute driven symbology based off of this post: https://community.esri.com/t5/commercial-blog/color-me-impressed-with-attribute-driven-symbology/ba-...

Which was great however this does not come across to ArcGIS Online when publishing this as a feature layer, I have found a few posts referencing how to do this with text in a pop-up using something similar to below:

var cd = $feature.condition

if (cd >= 0 && cd <= 0.99){return "#38A800"}
if (cd >= 1 && cd <= 1.99){return "#7ACB00"}
if (cd >= 2 && cd <= 2.99){return "#CEEE00"}
if (cd >= 3 && cd <= 3.99){return "#FFFF73"}
if (cd >= 4 && cd <= 4.99){return "#FF6600"}
if (cd == 5){return "#FF0000"}

but this does not seem to work when I try to set this within ArcGIS Online or ArcGIS Pro when using "Vary Symbology by attribute" and setting the expression to change the symbol colour :

Keiran_Bray_0-1672985965196.png

I've also tried using the when() function but could not get that to work either

Is it possible to set symbol type and using arcade to set polyline colour based off of specific integer values?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

It's sort of possible, but it's going to be tedious.

The "vary color by attribute" setting in Pro only really works for numeric values, and it will scale the color based on number and a color ramp. These values don't translate well to a legend, either. And as you've found, these don't carry over to AGOL.

What you're really trying to do is create unique symbols based on two fields. AGOL won't let you do this and treat things as categories; you can only use multiple fields with numeric values, not two categorical fields.

The best you can do is base the symbology on an expression:

var cd = $feature.condition

var cd_cat = When(
    cd >= 0 && cd <= 0.99, 'good',
    cd >= 1 && cd <= 1.99, 'fair',
    cd >= 2 && cd <= 2.99, 'adequate',
    cd >= 3 && cd <= 3.99, 'poor',
    cd >= 4 && cd <= 4.99, 'bad',
    cd == 5, 'just the worst',
    'no value'
)

return `${$feature.surface} - ${cd_cat}`

 

But you'll run into a couple issues. First, if you have 5 surface types and 6 conditions, there are potentially 30 unique symbols you'll need to configure. Like I said, tedious.

Second, in AGOL, you only get to configure symbols for values that are present in the data. So of the 30 potential combinations, if only half are present when the symbology is configured, then you won't be able to set the symbology for the remaining combinations. If one of those appear later, it will not be symbolized correctly, and you'll need to open the layer to adjust the symbology to catch that new type.

There's a workaround for the second point, that you can set the symbology for non-present values in ArcGIS Pro and save the web map from there, but it's still going to be tedious.

On the other hand, if you don't classify that other field, AGOL can get you colors from one field and width from the numeric field, but this might not be what you want for your map.

- Josh Carlson
Kendall County GIS

View solution in original post

8 Replies
RussRoberts
Esri Notable Contributor

Can you share a sample of the pro project? 

0 Kudos
RussRoberts
Esri Notable Contributor

I did a quick dive in and was able to create a web map using a similar expression but it did take some manual web map JSON changes. It looked like Pro was writing out a property that was not in the CIM spec where the JSAPI expected.

Sample where I set the outline on a point with primitive overrides https://jsapi.maps.arcgis.com/apps/mapviewer/index.html?webmap=03d01db03bae43cb8b629a02997dcaaa

Sample using lines

https://jsapi.maps.arcgis.com/apps/mapviewer/index.html?webmap=7e72420e21a443818091ffb8d2cea9bb

0 Kudos
jcarlson
MVP Esteemed Contributor

It's sort of possible, but it's going to be tedious.

The "vary color by attribute" setting in Pro only really works for numeric values, and it will scale the color based on number and a color ramp. These values don't translate well to a legend, either. And as you've found, these don't carry over to AGOL.

What you're really trying to do is create unique symbols based on two fields. AGOL won't let you do this and treat things as categories; you can only use multiple fields with numeric values, not two categorical fields.

The best you can do is base the symbology on an expression:

var cd = $feature.condition

var cd_cat = When(
    cd >= 0 && cd <= 0.99, 'good',
    cd >= 1 && cd <= 1.99, 'fair',
    cd >= 2 && cd <= 2.99, 'adequate',
    cd >= 3 && cd <= 3.99, 'poor',
    cd >= 4 && cd <= 4.99, 'bad',
    cd == 5, 'just the worst',
    'no value'
)

return `${$feature.surface} - ${cd_cat}`

 

But you'll run into a couple issues. First, if you have 5 surface types and 6 conditions, there are potentially 30 unique symbols you'll need to configure. Like I said, tedious.

Second, in AGOL, you only get to configure symbols for values that are present in the data. So of the 30 potential combinations, if only half are present when the symbology is configured, then you won't be able to set the symbology for the remaining combinations. If one of those appear later, it will not be symbolized correctly, and you'll need to open the layer to adjust the symbology to catch that new type.

There's a workaround for the second point, that you can set the symbology for non-present values in ArcGIS Pro and save the web map from there, but it's still going to be tedious.

On the other hand, if you don't classify that other field, AGOL can get you colors from one field and width from the numeric field, but this might not be what you want for your map.

- Josh Carlson
Kendall County GIS
JenniferAcunto
Esri Regular Contributor

FYI - In one of the more recent updates to AGOL, you can now set the symbology of features that aren't present in the data. Simply click the plus icon in the unique symbols editor to add the value and label, and then style it as normal. 

2023-01-09_6-36-08.jpg

 

- Jen
jcarlson
MVP Esteemed Contributor

Oooo, that's exciting! Thanks for the heads up!

- Josh Carlson
Kendall County GIS
0 Kudos
VanessaSimps
Occasional Contributor III

We are trying to use this, however, see my coworker's post here. It feels like this isn't quite working as expected?  Any one else seeing what my coworker is seeing? 

 

https://community.esri.com/t5/arcgis-online-questions/arcade-statement-for-symbology-not-quot-sticki...

0 Kudos
Keiran_Bray
New Contributor II

Hey thanks all, ill take another looks this week at the above, I had a feeling it would be a bit tedious regardless of which way I was wanting to go with it, @JenniferAcunto i might take a look at the as well as another option to,

I'll keep this updated with what I find,

Cheers

Keiran 

0 Kudos
Keiran_Bray
New Contributor II

Thanks @jcarlson @JenniferAcunto that worked for what we needed to show, didn't end up being to tedious and it looks good now,

Thanks again all,

Keiran

0 Kudos