Set symbol color from RGB values in attribute table with Arcade

11097
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
AdrianWelsh
MVP Honored Contributor

Xander,

Thanks for writing that and responding. This method works on a manual basis where I have to go and assign each color. But not sure that is sustainable for a large dataset. Plus, my symbology in the TOC is not updating which makes me think it might not publish correctly in AGOL. In this screenshot:

AdrianWelsh_0-1611844879961.png

 

The centerline line is blue as it should be ("rgb(0,0,255)"). But in the TOC the centerline is the default light blue assigned in the original random symbology. The same goes for the outer green lines - rgb(0,255,0). They show as a light green (box culverts) in the TOC. 

Each line type I have has a red, green, and blue value. I was hoping to do an arcade expression to create the "rgb(red,green,blue)" value and apply to all my features at one time. Is that not possible (to where it will reflect in the TOC in order for me to publish correctly to AGOL)?

I have another layer I need to apply the same method to and it has 70 different symbol types (all indicated by r,g,b) that I need to apply. By hand this would take too long!

Thanks!

0 Kudos
AdrianWelsh
MVP Honored Contributor

Xander,

Thanks for writing that and responding. This method works on a manual basis where I have to go and assign each color. But not sure that is sustainable for a large dataset. Plus, my symbology in the TOC is not updating which makes me think it might not publish correctly in AGOL. In this screenshot:

(removed screenshot since it would not let me post. It is attached as an image)

 

The centerline line is blue as it should be ("rgb(0,0,255)"). But in the TOC the centerline is the default light blue assigned in the original random symbology. The same goes for the outer green lines - rgb(0,255,0). They show as a light green (box culverts) in the TOC. 

Each line type I have has a red, green, and blue value. I was hoping to do an arcade expression to create the "rgb(red,green,blue)" value and apply to all my features at one time. Is that not possible (to where it will reflect in the TOC in order for me to publish correctly to AGOL)?

I have another layer I need to apply the same method to and it has 70 different symbol types (all indicated by r,g,b) that I need to apply. By hand this would take too long!

Thanks!

(upload didn't work, trying to copy and paste smaller screenshot:

AdrianWelsh_1-1611845828384.png

)

 

Whoops! Sorry for the double post. I am not sure what happened there...

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @AdrianWelsh ,

In the post I shared the case was a little more complex. Ignore the white and green points and focus on the orange points. The color is based on an attribute value and scaled over a color range. In your case, you will just use the rgb attribute and construct the correct string to return.

You can use the RGB values you have stored as attributes and assign them to the symbology. I have noticed that the Arcade based symbology does not get reflected correctly in the TOC (although I haven't checked this in 2.7) and I don't think AGOL will take that symbology once published. 

There are some nice enhancements in the Map Viewer beta for symbology based on SVG (https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/do-more-with-symbols-in-map-viewer-b...) but this is based on point geometry as far as I can see.

0 Kudos
AdrianWelsh
MVP Honored Contributor

Xander,

Thanks for sharing that. I tried messing with the symbology in the map viewer beta but you're right, it is just for points at the moment. 

I did use my rgb values and assigned them as symbology (using Arcade with the expression of:

"rgb(" + Text($feature.igds_color_red) + "," + Text($feature.igds_color_green) + "," + Text($feature.igds_color_blue) + ")"

But, like we have seen before, it just changes the symbology on the map itself and not in the TOC (this is 2.7). When I published that to AGOL, it did not take my new symbol colors.

ArcGIS Pro 2.7 view:

AdrianWelsh_0-1611858803793.png

 

AGOL view:

AdrianWelsh_1-1611858874689.png

 

I suppose that I will have to manually change the colors of all my line types!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @AdrianWelsh ,

The behavior is as I expected. Maybe  @KoryKramer  knows when we may expect that the symbology is correctly represented in the TOC...

Hopefully, there will be support soon in the Map Viewer Beta to support this type of symbology.  

AdrianWelsh
MVP Honored Contributor

Xander,

I wonder if there is a way to use Python and arcpy to solve an issue like this when I have attributes of red, green, and blue in my table... But I do not know enough Python to make it through!

Looking at this information:

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/symbol-class.htm

There is a snippet showing:

import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])

p = arcpy.mp.ArcGISProject(os.path.join(relpath, "Symbol.aprx"))
m = p.listMaps('Map')[0]
lyr = m.listLayers("Study Areas")[0]
sym = lyr.symbology

sym.renderer.symbol.applySymbolFromGallery("Extent Transparent Wide Gray")
sym.renderer.symbol.color = {'RGB' : [255, 0, 0, 60]}
sym.renderer.symbol.outlineColor = {'CMYK' : [25, 50, 75, 25, 100]}
sym.renderer.symbol.size = 3

lyr.symbology = sym

p.saveACopy(os.path.join(relpath, "SavedOutput.aprx"))

 

Would someone know a way to change that line of "sym.renderer.symbol.color = {'RGB' : [255, 0, 0, 60]}" to something like "sym.renderer.symbol.color = {'RGB' : [$feature.red, $feature.green, $feature.blue, 60]}"? Or would that still present the same problems where the 'legend' in the TOC does not update?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @AdrianWelsh ,

The TOC will probably represent the symbology defined in the code, but as far as I can see it will only set a single symbol to all the features. You will need to create a unique value renderer and define the symbols reading the rgb values from the attributes. 

0 Kudos
KoryKramer
Esri Community Moderator

Hi @XanderBakker It looks like Ivan posted this last year, but I believe what you're seeing is this issue: https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwNDMxNg==  For anybody following this thread who is affected by this behavior, I would recommend visiting that link and clicking the Subscribe button:

KoryKramer_0-1612809628384.png

That increments the count of subscriptions for the bug which can help to prioritize it.  It will also set you up for notifications on status updates.

Cheers!

CraigWilliams
Esri Contributor

This case you're showing in the UI is Vary symbology by color—ArcGIS Pro | ArcGIS Desktop  which is for linking data values to a color not color values to a color. See Attribute-driven color in symbology—ArcGIS Pro | ArcGIS Desktop for color to color.

by Anonymous User
Not applicable

Hi Simon,

We've been doing some work with a council in your state and figured out the exact process of how this symbology can be defined in ArcGIS Pro. Not very straightforward, I admit. Also, as a few other clients were after the same process, I decided that it'd be best to share the process as a blog: https://community.esri.com/people/iermoshkinesriaustralia-com-au-esridist/blog/2020/02/27/setting-up... 

Also, it seems that the process does actually work and the colors are read from the attribute field, there's a bug that prevents the legend from being created: 

BUG-000104316: Attribute-driven symbology assigned to features is n..

Hope this helps.