RasterUniqueValueColorizer

Resumen

Represents a raster unique value colorizer.

Debate

If you change your current colorizer to the RasterUniqueValueColorizer, you will first have to set the appropriate field property value. Once you apply your field, the colorizer will automatically generate all the unique values. If, for whatever reason, new values are added to the raster, you will need to reset the colorizer so that all the values are added again.

You need to understand how unique values are managed in the colorizer so you can navigate through the class structure to change individual items and their values. The groups property returns a list of ItemGroup objects. Each ItemGroup represents a category of items that each have their own heading. By default, there is one ItemGroup. The items property returns a list of RasterItem objects. Once you have an item, you can change properties such as label and description. You can also modify the color for each item. The reason the values property is plural and returns a list is because you can also group items within an ItemGroup. Therefore, each item could have multiple values.

The following is one way to outline the class structure:

  • groups—Returns a list of ItemGroup objects
    • heading
    • items—Returns a list of RasterItem objects
      • color
      • description
      • label
      • values

Propiedades

PropiedadExplicaciónTipo de datos
colorRamp
(Lectura y escritura)

Provides access to the ColorRamp object.

ColorRamp
field
(Lectura y escritura)

A field that is used by the colorizer to determine the unique set of values.

String
groups
(Lectura y escritura)

A list of ItemGroup objects containing unique values.

List
noDataColor
(Lectura y escritura)

A Boolean that controls the display of missing values. If True missing values are displayed.

Dictionary
type
(Sólo lectura)

Returns a string that represents the colorizer type.

String
useDefaultSymbol
(Lectura y escritura)

A Boolean that controls the display of un-added values. If True, the features are displayed.

Boolean

Muestra de código

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