RasterItem

Synthèse

RasterItem provides access to item level information for a RasterUniqueValueColorizer.

Discussion

The RasterItem class allows you to change properties such as field and color.

The color property returns a Python dictionary. The dictionary has a single key that matches the color model name, and the value is a list of color properties. For example, the RGB representation of red is {'RGB' : [255, 0, 0, 100]}. The properties change depending on the color model. The last parameter for all color models is an alpha or opacity value. The alpha or opacity value behaves the opposite way of transparency in the application user interface. If you set this value to 100 in the dictionary, it will appear as 0% in the transparency control on the ribbon or in the Symbology pane.

You can read the value of all supported color models, but you can only modify a subset. The following is a list of supported color models:

  • {'CMYK' : [Cyan, Magenta, Yellow, Black, Alpha]}—Read/Write
  • {'HSL' : [Hue, Saturation, Lightness, Alpha]}—Read/Write
  • {'HSV' : [Hue, Saturation, Value, Alpha]}—Read/Write
  • {'RGB' : [Red, Green, Blue, Alpha]}—Read/Write
  • {'Lab' : [Lightness, a, b, Alpha]}—Read-only
  • {'Grayscale' : [Gray, Alpha]}—Read-only

Propriétés

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

Gets and sets the color for the item using a Python dictionary.

Dictionary
description
(Lecture et écriture)

Gets and sets the description for the item.

String
label
(Lecture et écriture)

Gets and sets the label for the item.

String
values
(Lecture seule)

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

List

Exemple de code

RasterItem example

The following script first checks if the colorizer is RasterUniqueValueColorizer. Next, it sets the field property to use a field called Class_name. It next iterates through each RasterItem in each ItemGroup and checks for the label value that equals Water. Finally, it set the color to be an RGB blue with a 50% transparency.

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

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

if sym.colorizer.type == "RasterUniqueValueColorizer":
    sym.colorizer.field = 'Class_name'
    for grp in sym.colorizer.groups:
        for itm in grp.items:
            if itm.label == "Water":
                itm.color = {'RGB': [0, 0, 255, 50]}

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