Select to view content in your preferred language

Graduated Colors Renderer Errors

1181
2
Jump to solution
08-20-2021 02:22 PM
JaredPilbeam2
MVP Regular Contributor

I have this small code to change a feature layer's symbology. I'm referencing this help doc.

When I try to change the break count I get a RuntimeError. And when I try to identify the classification field I don't seem to find it. Using a print statement, I identify other properties but not the field. The only thing i can think of is possibly because this field is set to a custom expression:

sym.png

sym2.png

 

for lyr in m.listLayers():
    if lyr.isFeatureLayer:
        sym = lyr.symbology
        
        if hasattr(sym, 'renderer'):
            #type of renderer 
            if sym.renderer.type == 'GraduatedColorsRenderer':
                #sym.renderer.breakCount = 4 -RuntimeError: Invalid breakCount 4
                print('break count: {}\nmethod: {}\nfield: {}'.format(sym.renderer.breakCount, 
                                                                        sym.renderer.classificationMethod, 
                                                                        sym.renderer.classificationField))

 
prints:
break count: 5
method: ManualInterval
field:
0 Kudos
1 Solution

Accepted Solutions
JaredPilbeam2
MVP Regular Contributor

The classification field has to be a number in order for the renderer to recognize it. It validated both with float and double. It will not work with text fields. I'm in contact with an ESRI analyst who is looking into why that is.

View solution in original post

0 Kudos
2 Replies
JaredPilbeam2
MVP Regular Contributor

Looking into this further, i realized this classification field I'm trying to identify is a from a joined table. If I use a field not from the joined table it works fine.

The 'USER_PATIENT_ZIP' field is not from a joined table, and it validates. But, the field I want is from a joined table, and it's invalid somehow.

if hasattr(sym, 'renderer'):
    if sym.renderer.type == 'GraduatedColorsRenderer':
        sym.renderer.classificationField = 'USER_PATIENT_ZIP'
        print('Zip OK')
        sym.renderer.classificationField = 'Blckgrp2020_iCareCountOfVaccinated_ALL_FirstDose_Black_PercentVa'
        print('Dose OK')

### Zip OK

### ---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
In  [193]:
Line 5:     sym.renderer.classificationField = 'Blckgrp2020_iCareCountOfVaccinated_ALL_FirstDose_Black_PercentVa'

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py, in _set:
Line 109:   return setattr(self._arc_object, attr_name, cval(val))

RuntimeError: Invalid classificationField : Blckgrp2020_iCareCountOfVaccinated_ALL_FirstDose_Black_PercentVa
---------------------------------------------------------------------------

 

 

 

0 Kudos
JaredPilbeam2
MVP Regular Contributor

The classification field has to be a number in order for the renderer to recognize it. It validated both with float and double. It will not work with text fields. I'm in contact with an ESRI analyst who is looking into why that is.

0 Kudos