Summary
The RasterClassBreak class represents a raster class break that is available to the RasterClassifyColorizer class.
Discussion
It provides access to individual class break properties such as label 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 a 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
Properties
Property | Explanation | Data Type |
color (Read and Write) | Gets and sets the color for the class break using a Python dictionary. | Dictionary |
description (Read and Write) | Gets and sets the description for the class break. | String |
label (Read and Write) | Gets and sets the label for the class break. | String |
upperBound (Read and Write) | Gets and sets the maximum value for the class break. | Double |
Code sample
The following script modifies the symbology of a raster layer that uses a raster classified colorizer. It sets the classificationField, breakCount, and noDataColor. Next, it iterates through each raster class break and modifies the upperBound, label, description, and color properties. The labels for each break are formatted to include the less than or equal symbol and thousands separators. The HSV colors for each raster class break are incremented by even intervals.
# -*- coding: utf-8 -*-
import arcpy
import os
import sys
import locale
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(relpath + r'\\RasterClassify.aprx')
m = p.listMaps('Map')[0]
l = m.listLayers('Raster1')[0]
sym = l.symbology
sym.colorizer.classificationField = "Value"
sym.colorizer.breakCount = 5
sym.colorizer.noDataColor = {'RGB': [255, 255, 255, 100]}
breakVal = 50
cv = 0
for brk in sym.colorizer.classBreaks:
brk.upperBound = breakVal
brk.label = "\u2264" + str(locale.format("%d", breakVal, grouping=True))
brk.description = "Description " + str(cv)
brk.color = {'HSV' : [cv, cv, cv, 100]}
breakVal +=50
cv += 40
l.symbology = sym
p.saveACopy(relpath + r'\\SavedOutput.aprx')