Hi,
I am a GIS Analyst/Urban Planner working with land use data. I have a standard land use symbology for use in different cities and counties.
I am trying to extract the hex codes from the layer symbology and add them as a new field. The script from this solution post by @JohannesLindner . The script works to add the label of my symbology layer to a new field:
import arcpy
layer_names = ["PW Zoning"]
aprx = arcpy.mp.ArcGISProject("current")
for name in layer_names:
# get the layer
layer = aprx.activeMap.listLayers(name)[0]
# get the symbology fields and items
renderer = layer.symbology.renderer
fields = renderer.fields
items = renderer.groups[0].items
# create a dict {values: label}
item_dict = {tuple(i.values[0]): i.label for i in items}
# add a new field
arcpy.management.AddField(layer, "PW_Zoning_Designation", "TEXT")
# insert the label values
with arcpy.da.UpdateCursor(layer, ["PW_Zoning_Designation"] + fields) as cursor:
for row in cursor:
key = tuple([str(x) for x in row[1:]]) # item.values stores values as string
try:
row[0] = item_dict[key]
cursor.updateRow(row)
except KeyError: # no symbology found
passI am curious how I would add the hex codes into this code to add a new field that would include the six-digit hex codes; RGB codes work too. Thanks for any help. I am new to arcpy and will be attending the Developer Conference in two months.
