0

I have been using the following code (works) to update the symbology of a layer in ArcGIS. Now, in addition to this, i need to change the thickness of the lines previously symbolized by using GraduatedColorsSymbology.

mxd = arcpy.mapping.MapDocument(mxdfile)
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "Plot", df)[0]
lyr.visible = True
lyr.transparency = 0
sym = lyr.symbology
sym.valueField = "GrossTons"
sym.classBreakValues = [0, 1000000, 5000000, 10000000, 20000000, 40000000, 60000000, 600000000]
sym.classBreakLabels = ["<1M", "1M to 5M", "5M to 10M", "10M to 20M", "20M to 40M", "40M to 60M",">60M"]
arcpy.mapping.ExportToJPEG(mxd, "Export.jpg", "PAGE_LAYOUT", resolution=800)
del mxd

But when I try to add the color and thickness part, it gives an error saying 'GraduatedColorsSymbology' object has no attribute renderer.

Code added:

sym = lyr.symbology
sym.renderer.breakCount = 7

breakVal = 100000000000
cv = 0
lw = 1
for brk in sym.renderer.classBreaks:
  brk.upperBound = breakVal
  brk.label = "\u2264" + str(locale.format("%d", breakVal, grouping=True))
  brk.description = "Description " + str(cv)
  brk.symbol.color = {'HSV' : [cv, 100, 100, 100]}
  brk.symbol.outlineColor = {'HSV' : [240-cv, 100, 100, 100]}
  brk.symbol.size = lw

  breakVal +=100000000000
  cv += 40
  lw += 0.5
lyr.symbology = sym

I didnt find any reference to this anywhere else. Is there a way to change the thickness and colors of lines in GraduatedColorsSymbology? Please avoid using

arcpy.ApplySymbologyFromLayer_management(lyr, symbologyLayer)

because this will not allow me to be flexible with changing class breakvalues.

pnkjmndhl
  • 794
  • 1
  • 9
  • 20

1 Answers1

2

Looking at the documentation on that symbol class, I don't see any .renderer property which is why you are getting that error. Looks to me like you ought to be iterating over sym.classBreakValues attribute.

Also, you might want to set the layer symbology in the mxd to graduated symbols, I don't know whether this will keep your color ramp though. You may have better luck by migrating to a Unique Value symbology, but I don't know. I do know that modification of symbology in arcpy is heavily restricted, see this post from late last year on the matter. I don't think that you can iterate over the symbology and modify each symbol individually at all.

Zack
  • 1,105
  • 9
  • 15