Trouble with ArcGIS Pro 2.3.2 sym.renderer.breakCount assignment

344
3
10-16-2019 06:40 AM
JohnMossing
New Contributor II

Experiencing trouble with ArcGIS Pro 2.3.2 sym.renderer to assign symbology to a layer in a map project using only python. I am automating map creation, and layer creation, symbolization. I am trying to assign symbology to a layer (polygons) using the GraduatedColorsRenderer. I update the renderer, classification method and assign it a field. Then I define the classBreakValues and the breakCount. I can only get one classification break even though i have defined 5 or more.

It appears that the sym.renderer.breakCount will not allow me to assign any value to it. Whenever I assign it to any integer it seems to not take it. When I print out the value of the sym.renderer.breakCount it is always set to 1 regardless of what I set it to. For the classification methods i have tried ManualInterval, EqualInterval, Quantile.

Here is my code:

for lyr in m.listLayers():
   if lyr.name == "Binning Analysis":
      sym = lyr.symbology
      sym.updateRenderer('GraduatedColorsRenderer')
      sym.renderer.colorRamp = aprx.listColorRamps('Blues (Continuous)')[0]
      sym.renderer.classificationMethod = 'EqualInterval'
      classBreakValues = [5, 15, 35, 60, 1000]
      classBreakLabels = ["1 - 5", "6 - 15", "16 - 35", "36 - 60", "> 60"]
      sym.renderer.breakCount = len(classBreakValues)
      #sym.renderer.breakCount = 5
      count = 0
      for brk in sym.renderer.classBreaks:
         brk.upperBound = classBreakValues[count]
         brk.label = classBreakLabels[count]
         count += 1
      lyr.symbology = sym

I also put this code in the ArcGIS Pro Python window with a bunch of debug print statements to make sure all of my assignments were valid. Every thing seems valid. But the one thing that keeps happening in the Python window:

sym.renderer.breakCount = 5 #### Or any other number does not matter print(sym.renderer.breakCount) 1 ### always outputs 1 no matter what i assign

Can anyone assist? Any help would be appreciated, thank you.

Jay

0 Kudos
3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

And there they said that they couldn't reproduce your issue using Pro 2.4.2, so it might be version related

0 Kudos
JohnMossing
New Contributor II

I was attacking this issue for 2 days trying different ways to code with sym.renderer. I discovered some other things and a work around for me.

Addition to this issue. I was getting the same issue when I tried to manually adjust the symbology using the Symbology menu. When I first open the menu it opens with Natural breaks selected, and with 5 classes. However it has the wrong field selected so the moment that I change the field to the one I need to symbolize by it changes the classes to 1. If I manually change the classes to anything other than one, it does not keep it. It reverts back to 1.

So this feature class/layer has over 117,000 rows/features in it. I have discovered that if I added a definition query to the layer reducing the number features then all of the above code seems to work fine. This is replicable using the symbology menu and using the arcpy code. The layer with the definition query is now manageable for the symbology menu manually when I change the number of classes in there the change sticks. So it appears to be a problem relating to too many features in the feature class or too large of a sample size for the sym.renderer to manage.

I can use the definition query, is there a way to except certain values or increase the sample size of sym.renderer because maybe defintion query work around will not always be viable?

0 Kudos
MeganCuller1
New Contributor

I ran into the same problem in 2.7.2. I found that it only happened if the layer is part of a join. If I removed the join or copied the features to make the join permanent, I was able to change the number of categories with no issues.

0 Kudos