ItemGroup

Synthèse

ItemGroup provides access to group level information for a UniqueValueRenderer.

Discussion

The ItemGroup class allows you to change a heading value for a group and more importantly provides access to the individual items in each group.

Propriétés

PropriétéExplicationType de données
heading
(Lecture et écriture)

Gets and sets the heading string for the group.

String
items
(Lecture et écriture)

Gets and sets a list of Item or RasterItem objects associated with the group.

Object

Exemple de code

ItemGroup example

The following script first changes the renderer to aUniqueValueRenderer. Next, it sets the fields property to use a single field called Percent. It next iterates through each Item in each ItemGroup and sets the RGB color to red and the alpha, or opacity, value to match the Percent value of each feature. Finally, it labels each value, sets the symbology back to the layer and saves the output.

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

p = arcpy.mp.ArcGISProject(relpath + r'\\UniqueValue.aprx')
m = p.listMaps('Map')[0]
l = m.listLayers('PercentCover*')[0]
sym = l.symbology

sym.updateRenderer('UniqueValueRenderer')
sym.renderer.fields = ['Percent']
for grp in sym.renderer.groups:
    for itm in grp.items:
        transVal = itm.values[0][0] #Grab the first "percent" value in the list of potential values
        itm.symbol.color = {'RGB': [255, 0, 0, int(transVal)]}
        itm.label = str(transVal) + '%'

l.symbology = sym
p.saveACopy(relpath + r'\\SavedOutput.aprx')