Skip to main content

RasterClassifyColorizer

Summary

Represents a raster classify colorizer.

Discussion

The properties behave in a similar manner to the options exposed in the application. For example, changing the number of classes will automatically adjust the break values and their labels. If you change the upperBound property of a RasterClassBreak, the classificationMethod automatically changes to ManualInterval. You would also need to manually update the labels property accordingly.

Properties

Name Explanation Data type

breakCount

(Read and Write)

An integer that represents the number of classes to be used with the current classification method.

Integer

classBreaks

(Read and Write)

A list of RasterClassBreak objects that provides access to individual properties such as label and color.

List

classificationField

(Read and Write)

A string that represents a valid field name used for the layer's classification method.

String

classificationMethod

(Read and Write)

A string that represents a valid classification method. The valid values are as follows:

  • DefinedInterval—Defined Interval

  • EqualInterval—Equal Interval

  • GeometricInterval—Geometric Interval

  • ManualInterval—Manual Interval

  • NaturalBreaks—Natural Breaks (Jenks)

  • Quantile—Quantile

  • StandardDeviation—Standard Deviation

String

colorRamp

(Read and Write)

Provides access to the ColorRamp object.

ColorRamp

lowerBound

(Read and Write)

A double that represents the minimum value of the symbolized classificationField to be displayed.

Note:

The value of the lowerBound should only be set to a value within the range of the first class break, otherwise it will fail. The maximum value gets modified in the last class break by changing the upperBound property.

Double

noDataColor

(Read and Write)

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

Dictionary

type

(Read only)

Returns a string that represents the renderer type.

String

Code sample

RasterClassifyColorizer example 1

The following script first tests if the layer's symbology supports a colorizer property and then confirms if the renderer is a RasterClassifyColorizer. Next. it changes the classificationField and breakCount. Finally, it changes ColorRamp to a color ramp named Cyan to Purple.

import arcpy
import os
import sys

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

if hasattr(sym, 'colorizer'):
    if sym.colorizer.type == 'RasterClassifyColorizer':
        sym.colorizer.classificationField = 'Value'
        sym.colorizer.breakCount = 7
        sym.colorizer.colorRamp = p.listColorRamps('Cyan to Purple')[0]
        l.symbology = sym

p.saveACopy(relpath + r'\\SavedOutput.aprx')
RasterClassifyColorizer example 2

The following script modifies the symbology of a raster layer that uses a raster classified colorizer. It sets 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')