Select to view content in your preferred language

Pro equivalent to layer.symbology.excludedValues

810
1
08-11-2023 06:19 AM
efujioka
Occasional Contributor

Hello,

I'm migrating a Ptyhon script for ArcGIS 10.x to ArcGIS Pro 2.9. There is one 10.x code that I can't find equivalent to Pro.

Spoiler
# ArcGIS 10.x
import arcpy
layer = ...
if layer.symbologyType == "RASTER_CLASSIFIED":
    layer.symbology.excludedValues = '0'

where layer is a raster. What I want to do is not to give a color to raster cells whose value is 0.

If I open an ArcGIS Pro project, I can do this by going to the Symbology pane and Advanced symbology options. Then, enter "0" to "Data exclusion" box.

Does anyone know how to do this in a Python script for ArcGIS Pro 2.9 (or 3.x; I have both versions)?

Thanks,

0 Kudos
1 Reply
by Anonymous User
Not applicable

This may be set in the noDataColor of the colorizer. Not sure what type symbology type (stretch, classify, unique, etc.,.) you are using so find the one and adapt the example.

sym.noDataColor = {'RGB': [0, 0, 0, 0]}

rasterclassifycolorizer-class 

import arcpy


p = arcpy.mp.ArcGISProject(r'CURRENT')
m = p.listMaps('Map')[0]
l = m.listLayers('rastermaster')[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]
        sym.noDataColor = {'RGB': [0, 0, 0, 0]}
        l.symbology = sym

 

0 Kudos