Set symbol color from RGB values in attribute table with Arcade

11098
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
GabrielMarcus1
Occasional Contributor II

Hey ESRI, some real world examples for writing Arcade code would be ideal. I'm not sure many working professionals say "Hmm, I'm going to learn Arcade today instead of working on my deadlines...." 

I spent several hours this weekend trying to find the answer for my problem in Arcade. Can discrete point colors not on a color scheme be displayed using Arcade?

If you have only one or a few different symbols, you can go into "format point symbol" (in my case), then click Properties, then layers. Expand Appearance.  Click the "database +" icon to the right of color. Select the field that contains your color. Press OK. Click Apply.   Repeat for your other symbols. 

The  implementation of "Vary Symbology by Attribute" is confusing unless it's done symbol by symbol. 

I imagine even if I did create an Arcade script to return the color, the color scheme may over-ride the attribute values.

When I am in the format point symbol and have chosen a symbol, and then go to the 3 bars in the upper right and choose "Allow symbol property connections", it would have made more sense to go to "properties">"layers" where I can choose which fields have my color info, versus the "vary symbol by attribute" window, which doesn't have the ability to create discrete colors based on the attribute. 

I have a mix of hex values (#FF0000") color names (Green) and RGB values (255,0,255) in my marker_color field. Thankfully, ArcGIS Pro read each color with no difficulties! I didn't have to translate my different formats into one. Thanks! I saw a lot of python and VBscript examples, which I'm glad I didn't have to use. 

I recommend:

  • Creating a cookbook blog entry that contains commonly used Arcade scripts for Pro. Comment the crap out of it so we can learn.
  • Expressing the limitations on what can't be done in Arcade.
  • Consider adding the "database plus" icon to live in the "Vary symbology by attribute" screen as well. Having the color scheme override the values in the table isn't useful to me. 

I'm hoping to be able to vary the symbol itself based on an attribute table. I don't think that's possible yet. 

0 Kudos
deleted-user-g91W1rr8qw5g
New Contributor

"I'm hoping to be able to vary the symbol itself based on an attribute table. I don't think that's possible yet."

This is currently frustrating me in a pretty big way. I'm currently trying to set three different colors for three different ranges of values from an attribute table. Were you able to figure out if you can use Arcade to vary the symbol by attribute table values? It seems like I will just have to try to set the discrete colors in ArcGIS Online. I hope I can. 

0 Kudos
CraigWilliams
Esri Contributor

This is achievable as well using the attribute driven color approach. What issues are you having?

0 Kudos
John_RMellor__GISP
Occasional Contributor

I'm having the same issue.  If field1 <= 2 or field2 <=2 or field3 <=2 show the point as red.  If field1=3 or field2=3 or field3=3 show the point as yellow.  If field1=4 or field2 =4 or field3 =4 show the point as orange. Show any other point as green. I can't seem to get the expression right in the symbology for the feature class.  

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Mellor, John ,

Your case is actually different from the one the OP posted.  Yours could be solved like this:

var field1 = 4; // point to your field1
var field2 = 3; // point to your field2
var field3 = 2; // point to your field3

var result = "green";
if (field1 <= 2 || field2 <= 2 || field3 <= 2) {
    result = "red";
} else if (field1 == 3 || field2 == 3 || field3 == 3) {
    result = "yellow";
} else if (field1 == 4 || field2 == 3 || field3 == 3) {
    result = "orange";
}

return result;

(shouldn't the yellow and orange assignments be switched, because now you will get red-yellow-orange-green and a more logical color range would be red-orange-yellow-green?)

SimonJackson
Occasional Contributor III

+1 with same issue.

  • I prebaked a rgb(R,G,B) value into a new string field.
  • All values look good to me
  • Enable symbol property connections
  • Can't pick field from drop down
  • Arcade does not seem to flow through.

Similar scenario - I have property zones that I need to colour by the RGB value field.

Running ArcGIS Pro 2.4 Beta 2

Would love to see some examples, sure we can't be far off?

XanderBakker
Esri Esteemed Contributor

This really does not seem to be working as described in the documentation. Kory Kramer‌, if you have a moment could you clarify how to make this work?

AdrianWelsh
MVP Honored Contributor

@XanderBakkerand @KoryKramer  was this ever resolved? I am using 2.7 and it still seems to not follow the procedures outlined in the help documentation.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @AdrianWelsh ,

 

I wrote something explaining the procedure a while ago because it is possible to do this for a couple of versions now. 

https://community.esri.com/t5/arcgis-pro-questions/color-green-for-type-a-scale-of-yellow-red-for-ty... 

 

Let me know if this helps.