In my Pro project, I have 8 maps with 3 layers each. I'm writing a script that iterates the layers in each map, and changes the break values of these layers. There is one more step where I'd be grateful for some direction. And that is with setting multiple classificationFields.
I know how to set the break values using one classificationField, anyway. I'm not sure I'm doing this right, but in order to give each layer its particular classificationField which corresponds to that particular map I've created a list.
#create fields list. for every map, change the symbology based on its corresponding field
sym.renderer.fields = ['VaccPercentageTotPop', 'VaccPercentage0to18', 'VaccPercentage11to14',
'VaccPercentage12to18', 'VaccPercentage14to16',
'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']
I'm using sym.renderer.fields because it seems to allow a list, which I'm referencing from this SE post. In the Pro docs I don't see any help with multiple fields. This will throw an error with a list:
sym.renderer.classificationField = ...
The following script iterates the layers and the maps successfully, but nothing happens to the layers.
import arcpy
aprx = arcpy.mp.ArcGISProject(r'\\path to\TestDelete.aprx')
def values():
for map in aprx.listMaps():
print(f'map: {map.name}')
layers = map.listLayers()
for layer in layers:
sym = layer.symbology
if hasattr(sym, 'renderer') and layer.name.startswith('BaseLayer'):
sym.updateRenderer('GraduatedColorsRenderer')
print(f'Updated Graduated colors renderer: {layer}')
Renderer = sym.renderer
classbreakvalues = [40, 45, 56.8, 100]
classbreaklabels = ['0-40%', '41-45%', '46-56.8%', '56.9-100%']
Renderer.breakCount = len(classbreakvalues)
print(f'Set the break count value: {layer}')
#Renderer.classificationMethod = 'Manual Interval'
#create fields list. for every map, change the symbology based on its corresponding field
sym.renderer.fields = ['VaccPercentageTotPop', 'VaccPercentage0to18', 'VaccPercentage11to14', 'VaccPercentage12to18',
'VaccPercentage14to16', 'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']
i = 0
for brk in Renderer.classBreaks:
brk.upperBound = classbreakvalues[i]
brk.label = classbreaklabels[i]
i+=1
layer.symbology = sym
aprx.save()
values()