Select to view content in your preferred language

Combining symbol classes using Arcpy

275
0
05-18-2023 01:01 AM
OllyD
by
New Contributor II

Hello,

I'm trying to write a test script which looks at a layers attributes and then applies different colours based on a given attribute. This is the script I have so far:

 

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.activeMap
lyr = aprxMap.listLayers('Q_ARCHAEOLOGY')[0]
sym = lyr.symbology


sym.updateRenderer('UniqueValueRenderer')
sym.renderer.fields = ['LAYER_NAME']
for grp in sym.renderer.groups:
    for itm in grp.items:
        attrVal = itm.values[0][0]

        if attrVal == "ARCH_LAYER":
            itm.symbol.color = {"RGB": [249, 30, 22, 100]}      # red
            itm.symbol.outlineColor = {"RGB": [0, 0, 0, 0]}     # null colour for symbol outline
            itm.symbol.size = 5
            itm.label = str("layer")
        elif attrVal == "ARCH_PRE_EX":
            itm.symbol.color = {"RGB": [78, 247, 30, 100]}      # green
            itm.symbol.outlineColor = {"RGB": [0, 0, 0, 0]}     # null colour for symbol outline
            itm.symbol.size = 5
            itm.label = str("preex")
        elif attrVal == "ARCH" or attrVal == "ARCHAEOL":
            itm.symbol.color = {"RGB": [70, 207, 50, 100]}      # green
            itm.symbol.outlineColor = {"RGB": [0, 0, 0, 0]}     # null colour for symbol outline
            itm.symbol.size = 5
            itm.label = str("arch")


lyr.symbology = sym

aprx.save()

 

 

Whilst for the most part this script works the issue I have is that it creates two symbol classes labelled "arch", whilst I want the attributes ARCH and ARCHAEOL combined into one symbol class for the purpose of legend tidiness on figures. 

 

How do I combine these into one class? Is there a way replicate an Arcade expression combining the two in python?

 

Thanks

Tags (3)
0 Kudos
0 Replies