How to color features specific HEX colors using conditional symbology with arcade

1785
4
04-26-2023 10:50 AM
Labels (2)
e_ruda
by
New Contributor

Hi all, I'm a newbie to ArcGIS Pro, and most of the things I know I've either taught myself, read about online, or I remember from a bit of ArcMap training I had a few years ago. I have a hyper-specific question, and I'm struggling to find other community posts that even sort-of help. Apologies in advance if my jargon is wrong.

Basically, I have a feature class with a bunch of polygons (rooms within a building), and I am trying to display the symbology by the "Unit" that's assigned to that polygon. That much is simple. However, I have a pre-determined list of HEX color codes that are assigned to each unit, and I'd like to be able to use that list of color codes in Arc so that I can keep everything consistent. I can add the colors manually, but obviously that's super time consuming and doesn't help if I add more values and everything re-randomizes. I'd like to build an expression in Arcade that just automatically colors my map, as needed. I don't think Arc takes HEX color codes, so I can just convert to rgb, that's not a big issue. Below is my code that I've pieced together from other help forums, but it's not accomplishing what I need.

e_ruda_0-1682530871940.png

Like I mentioned before, I'm a complete newbie, and even newer to Arcade coding, so any and all help is appreciated. Thanks in advance!

Edit: I have ArcGIS Pro 2.7.0 if that helps!

0 Kudos
4 Replies
DanielMiranda2
Occasional Contributor

Just to make sure, are you entering this expression in the Vary symbology by attribute section of the symbology pane under color?

DanielMiranda2_0-1682537772105.png

 

If so, this help doc explains how the RGB code should be output. It needs to be a string, Attribute-driven color in symbology—ArcGIS Pro | Documentation with just rgb(r, g, b).

 

So your code as a starting point could look like this:

if($feature.UNIT == "unit A"){
   return "rgb(230, 149, 167)"
}

 

 

0 Kudos
e_ruda
by
New Contributor

Hi thank you so much! So when I run that code, it does correctly identify the right unit, but it changes the value and the label, when I want it to change the actual symbol. This is what I'm getting back:

e_ruda_0-1682539402762.png

and this is the color I'm expecting for the symbol:

e_ruda_1-1682539431742.png

 

 

0 Kudos
JesseWickizer
Esri Contributor

If you have color values stored in the attribute table, you can use symbol property connections to change the color of each feature based on attributes. The colors should be formatted like this:

For hex values: #eb4034

For rgb values: rgb(123,45,67)

Check the box to Allow symbol property connections in the Symbology pane, Vary symbology by attribute tab:

JesseWickizer_0-1682616200531.png

In the Primary symbology tab of the Symbology pane, select Single Symbol and click on the symbol to edit. 

JesseWickizer_1-1682616291868.png

Click the connection icon next to the fill color.

JesseWickizer_3-1682616373353.png

Pick the field containing the color values for each record, or create a more complex formula if you can't add hex values to the attribute table. You may also need to use a formula to format the color values if you don't have the # character in front of the hex values, or if the RGB values are split into 3 separate fields.

JesseWickizer_4-1682616460889.png

The fill colors are derived from the HEX field in the data:

JesseWickizer_5-1682616510908.png

 

 

0 Kudos
Adam_Inglis
New Contributor II

Is it possible for the hex colours from the attribute table to be displayed in the Contents pane, so that they can be reflected in a layout legend?

Adam_Inglis_0-1711489492134.png

Adam_Inglis_1-1711489510233.pngAdam_Inglis_2-1711489521411.png