Select to view content in your preferred language

Help! Graduated Colors Symbology Automation and Classification

1356
3
10-09-2012 04:42 PM
ShaneArmour
Deactivated User
Does anyone know how to apply the graduated colors symbology using ArcPy?

I will use manual classification and apply percentages rather than values. For each map i make, i need to represent 1%, 5%, 50%, 75% ranges of the max value in the data. The problem starts when I import symbology from a layer. I can import the symbology and labels, but the percentage ranges represent the previous data.

Can i set the classification to represent these percentages using ArcPy?

Thanks!!
Tags (2)
0 Kudos
3 Replies
ArkadiuszMatoszka
Frequent Contributor
After importing symbology from .lyr use symbology attribute of layer, and set classBreakValues parameter (it should be sorted list of break values). So it should look like:
...
lyr = arcpy.mapping.ListLayers(mxd, 'layer_name_in_mxd)[0]
if lyr.supports('SYMBOLOGY'):
  lyr.symbology.valueField = field_name
  lyr.symbology.classBreakValues = [0, 0.01, 0.05, 0.5, 0.75, 1]
  lyr.symbology.classBreakLabels = ['<1%', '1-5%', '5-50%', '50-75%', '>75%']
...
arcpy.RefreshActiveView()


Regards.
Arek
0 Kudos
ArkadiuszMatoszka
Frequent Contributor
Use cursor to extract max value then after importing symbology from .lyr use symbology attribute of layer, and set classBreakValues parameter (it should be sorted list of break values). So it should looks something like:
...

with arcpy.da.SearchCursor(lyr, (field_name)) as cur:
  max_v = max([v[0] for v in cur])
...
if lyr.supports('SYMBOLOGY'):
  lyr.symbology.valueField = field_name
  lyr.symbology.classBreakValues = [0, 0.01 * max_v, 0.05 * max_v, 0.5 * max_v, 0.75 *max_v, max_v]
  
...
arcpy.RefreshActiveView()

Regards,
Arek
0 Kudos
ShaneArmour
Deactivated User
Thank you!!!!

I am working on the automation now. I'll let you know if it works.
0 Kudos