Item

Resumen

Item provides access to item level information for a UniqueValueRenderer.

Debate

The Item class allows you to change properties such as label and description and also provides access to the individual Symbol for each item.

Propiedades

PropiedadExplicaciónTipo de datos
description
(Lectura y escritura)

Gets and sets the description for the item.

String
label
(Lectura y escritura)

Gets and sets the label for the item.

String
symbol
(Lectura y escritura)

Gets and sets the symbol associated with the item.

Symbol
values
(Sólo lectura)

Gets the list of values associated with each item. There are multiple values when items are grouped within a group.

List

Muestra de código

Item 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')