Friday 22 April 2016

arcmap - Changing graduated color class values with ArcPy?


I am trying to use python to adjust my graduated color symbols' class breaks and labels. The layer is a query layer tied to an SQL DB and I want to be able to execute my python (after the database has been updated) to automatically author a map and have the layer/legend reflect the changes made in the database. I've tried this script but it doesn't work and I get an error I don't recognize.


import arcpy
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

lyr = arcpy.mapping.ListLayers(mxd, "Unsafe_Driving", df)[0]
if lyr.symbologyType == "GRADUATED_COLORS":
lyr.symbology.valueField = "CSA.DBO.%Unsafe_Driving_1.VARIANCE"
lyr.symbology.classBreakValues = [-.01, .01, .0866]
lyr.symbology.classBreakLabels = ["-8.66% to -1.00%", "-.99% to 1.00%","1.01% to 8.66%"]

arcpy.RefreshActiveView()


Runtime error Traceback (most recent call last): File "", line 7, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects_base.py", line 87, in _set return setattr(self._arc_object, attr_name, cval(val)) RuntimeError




The goal here is to have 3 classes:



  1. Lowest value to -1.00%

  2. -.99% to 1.00%

  3. 1.01% to the highest value.


Since the lowest and highest values can change, do I need to use a query to dynamically insert those into the lyr.symbology.classBreakValues?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...