Select to view content in your preferred language

Changing layer symbology

5473
6
08-06-2013 06:21 AM
SuzanneGriffith
Emerging Contributor
I???m trying to change the class break values for a layer that has graduated colors symbology.  The layer has three data ranges and the classification method is natural breaks.

Here is the code I???m trying to run:

import arcpy
from arcpy import env
mapdoc = arcpy.mapping.MapDocument(r"C:\data\Population.mxd")
df = arcpy.mapping.ListDataFrames(mapdoc, "layers")[0]
lyr = arcpy.mapping.ListLayers(mapdoc, "Population", df)[0]
lyrFile = arcpy.mapping.Layer(r"C:\data\update_layer.lyr")
arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True)
lyr.symbology.classBreakValues = [1, 100, 250, 550]


When I run the script line-by-line in ArcMap???s Python window everything seems to work, up to and including the UpdateLayer line; the colors and data breaks change correctly and the layer still has natural breaks.  But running the last line gives me the following error:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 87, in _set
    return setattr(self._arc_object, attr_name, cval(val))
RuntimeError


At that point when I go to the symbology tab of the layer???s properties, there are three ranges but they are listed as 0-100, 0-250 and 0-550 and they have no symbols associated with them.

When I start all over again and re-run everything and update the layer but instead try to change the number of classes with the line

lyr.symbology.numClasses = 4


I get the same error message as above.  When I try to access the layer???s properties a warning in ArcMap pops up:  ???Encountered an improper argument.???  If I click OK on the warning it lets me into the symbology tab but the dialog areas for all of the options under Quantities (Graduated colors, graduated symbols, etc) have the heading ???NO DESCRIPTION" and are otherwise blank.

This seems like a pretty straightforward script.  I can't figure out where the problem is.  I'm hoping someone can help me figure this out.
Tags (2)
6 Replies
JeffBarrette
Esri Regular Contributor
Hello,

Curious, why are you using UpdateLayer when you can directly change the classbreak values and descriptions directly.  Is it because the initial layer does not use the graduated symbols symbology?  Make sure the update layer also uses the right renderer.

Could it be possible that you are updating a layer with symbology from a layerfile that has classbreak information that doesn't match you underlying source data?

Before changing the classbreak values and descriptions, did you try:

lyr.symbology.reclassify()


Jeff
0 Kudos
SuzanneGriffith
Emerging Contributor
Hi, Jeff,

The reason I�??m doing it this way is because I want to specify the number of class breaks depending on the maximum value.  I also want specify the values of the class breaks and the colors used in the symbology. 

In this case, the original layer has four ranges.  The update layer is based the same data source and has three ranges.  Updating the layer changes the number of class breaks and gives me the colors I want.  But when I try to specify the maximum value shown in the legend I run into trouble.

I re-ran it with the reclassify line as you suggested but got the same error message when I then tried to update classBreakValues.

I also re-ran it skipping the 6th and 7th lines to see if the problem is with the updating, but I get the same error. 

Suzanne
0 Kudos
JeffBarrette
Esri Regular Contributor
What do you get when you run:

import arcpy
mapdoc = arcpy.mapping.MapDocument(r"C:\data\Population.mxd")
df = arcpy.mapping.ListDataFrames(mapdoc, "layers")[0]
lyr = arcpy.mapping.ListLayers(mapdoc, "Population", df)[0]
lyrFile = arcpy.mapping.Layer(r"C:\data\update_layer.lyr")
arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True)
print lyr.symbologyType


What does the print statement give you?
0 Kudos
SuzanneGriffith
Emerging Contributor
It says:

>>> print lyr.symbologyType
GRADUATED_COLORS
0 Kudos
SuzanneGriffith
Emerging Contributor
Hi, Jeff,

Just following up to see if you have any additional advice.

Suzanne
0 Kudos
SimonS
by
New Contributor
I think the problem, as pointed out by Cheffing in this thread, is that setting the symbology values does not work on layers with joined tables.
lyr.symbology.classBreakValues = [1, 100, 250, 550]


Without the join it works fine.

Does anyone know of a workaround?

Hopefully ESRI can look into this problem.