I'm working on an arcpy script that will automatically set up excluded values, class breaks values, and class break labels in a series of raster layers. A simplified version of part of my code is visible below:
mxd = arcpy.mapping.MapDocument(r'C:\Users\djh\Desktop\GIS Temp\test.mxd') df = arcpy.mapping.ListDataFrames(mxd) symbology_lyr = (r'C:\Users\djh\Desktop\GIS Temp\test.lyr') raster_name = (r'C:\Users\djh\Desktop\GIS Temp\test.gdb\test') levels = [31.0, 32.0, 33.0, 34.0, 35.0] class_break_labels = ['31.0 - 32.0', '32.0 - 33.0', '33.0 - 34.0', '> 34.0'] layers = arcpy.mapping.ListLayers(mxd, data_frame=df) for lyr in layers: if lyr.isGroupLayer: for sublyr in lyr: if sublyr.name == raster_name: arcpy.ApplySymbologyFromLayer_management(sublyr, symbology_layer) if sublyr.symbologyType == "RASTER_CLASSIFIED": sublyr.symbology.excludedValues = '0 - ' + str(levels) sublyr.symbology.classBreakValues = levels[1:] sublyr.symbology.classBreakLabels = class_break_labels
When I run up to the Apply Symbology From Layer line, it works fine and updates the symbology accordingly, but when I include the last 'if' loop, I get the following error on the last line of the above snippet:
ValueError: Number of label classes don't match number of class breaks
I included a print statement to get the difference between the lengths of levels[1:] and class_break_labels (both lists), and for every iteration it was 0, so I don't see how the numbers could possibly not match.
I appropriated the last 'if' loop from this Esri help page.
Has anyone encountered this before?