Set symbol color from RGB values in attribute table with Arcade

11397
22
06-13-2018 02:49 PM
ralphholmes
New Contributor III

So....

I have a zoning maps for all the municipality over a  tri-county area. I have taken the time to code into the attributes an RGB value and the corresponding HEX code for the appropriate color based off of the APA's Land based Classification scheme this way every R1 zone weather its in muni A or muni Z has the same color. I have around 200 unique features and i really would like to not have to copy and paste my HEX codes into the symbol color picker one at a time. 

this is a topic that has come up before but is not resolved satisfactorily in this thread 

Set symbol color from RGB values in attribute table 

it also is mostly for arc desktop.

In Pro I have the 

Attribute-driven color in symbology—ArcGIS Pro | ArcGIS Desktop 

which tells me that i must supply "Arcade expression that returns a string. "

all well and good and about as helpful as mud... 

Does the string have to be formatted as just R,G,B

Concatenate( "$feature['Units_in_M$.R'] + ", " + $feature['Units_in_M$.G'] + ", " + $feature['Units_in_M$.B'])

 or 

(R,G,B)

Concatenate( "(" + "$feature['Units_in_M$.R'] + ", " + $feature['Units_in_M$.G'] + ", " + $feature['Units_in_M$.B'] + ")" )

or

rgba(r, g, b,a)

Concatenate( "rgba(" + $feature['Units_in_M$.R'] + "," + $feature['Units_in_M$.G'] + "," + $feature['Units_in_M$.B'] + ",0" +")" )

 

All of these verify as correct expressions yet none of them change the color of a symbol to the correct color that I am referencing in my attribute table. 

I know it says that while the expression may be valid it may not symbolize correctly if the resulting text expression is not a real rgb color. I have also tried the above combinations with just hard coded (255,0,0) which should return red but it does not.

Also

As far as I can tell this may be just as time consuming as inputting the correct color by hand as there does not appear to be a way to apply this code to all 200 features. 

Am I missing something? 

Please help

22 Replies
SimonJackson
Occasional Contributor III

Your a gun Ivan! Nice work.

0 Kudos
NickMiddleton
New Contributor III

I am sure this worked in Desktop and you can definetely make this work in QGIS.  Note that the bug was first identified in 2017.

Nick M.

0 Kudos
CraigWilliams
Esri Contributor

The text out of the expression needs to match the examples in the above linked help topic. If you're specifying alpha, you need a value from 0 to 1 with 0 being fully transparent and 1 being opaque. You also don't need the concatenate function in this case

So, use:

"rgb(" + $feature['Units_in_M$.R'] + "," + $feature['Units_in_M$.G'] + "," + $feature['Units_in_M$.B']

-or-

"rgba(" + $feature['Units_in_M$.R'] + "," + $feature['Units_in_M$.G'] + "," + $feature['Units_in_M$.B'] + ",1)"

Depending on what you're fields are, you may need to use the Arcade Text() function to format numbers to correct format as a string.