1

I develop a python script tool to adapt the symbology of a set of shapefiles based on a given symbology template (layer file).

These are the properties that should be changed:

Number of classes and colors: using the ApplySymbologyFromLayer() function. The symbology template has 4 classes set to natural breaks and the colors are set manually to specific RGB values (green, brown, red, blue), there is no color scheme used.

Class break values and labels: calculated based on statistical values of each shapefile (in the code below entered arbitrary values)

After using the ApplySymbologyFromLayer(), the shapefile is set to 4 classes, natural breaks, and the specified colors. But when I then set the class break values and labels, the colors are reset to the default color scheme. I cannot use the ApplySymbologyFromLayer() afterwards, as then the classification scheme is reset.

EDIT: Obviously the problem are the manually set colors, as the colors remain consistent when a color scheme is used. But I need to apply the specific color values.

Why are the manually applied colors reset and is there a Workaround for this?

Here is my code:

import arcpy
inptShapefiles = arcpy.GetParameterAsText(0)
symbologyTemplate = arcpy.GetParameterAsText(1)

shapefiles = inptShapefiles.split(';') 
for shp in shapefiles:
    name = os.path.splitext(os.path.basename(shp))[0]
    lyr = arcpy.MakeFeatureLayer_management(shp, name)
    arcpy.ApplySymbologyFromLayer_management(lyr, symbologyTemplate)
    lyr.getOutput(0).symbology.classBreakValues = [1, 100, 200, 300, 400]
    lyr.getOutput(0).symbology.classBreakLabels = ["Class A", "Class B", "Class C", "Class D"]
    arcpy.SaveToLayerFile_management(lyr, "E:/temp/" + lyr.getOutput(0).name, "RELATIVE")
2
  • Create a new 4-colour scheme and use that in your template layer. The new layer should reference that new scheme so the colours shouldn't change after being classified
    – Midavalo
    Mar 9, 2016 at 17:08
  • Many thanks, that worked! You could post it as answer, then I can mark the question as solved.
    – the_chimp
    Mar 10, 2016 at 5:26

1 Answer 1

3

Create a new 4-colour scheme and use that in your template layer.

Set the new layer to reference that 4-colour scheme and the colours shouldn't change after being classified.

enter image description here

4
  • As my feature layer represents polylines, I am wondering if there is a possibility that the strength of the line (e.g. 2) can be applied too. I already tried within the symbology tab to select all classes - right click - properties for all elements, and setting the strength of the line. But the resulting polyline layer has always a strength of 1.
    – the_chimp
    Mar 10, 2016 at 9:21
  • Change them one at a time to 2, and save in your layer file. These should load via your script as lineweight 2 when you apply from layer file. I'm unsure why you can't use Properties for All Symbols here. I can only set properties individually. I have found that if I have too many to modify I can just set to 1 class break, set my symbol size and OK, then reopen layer properties and split into the required number of class breaks. This will keep the symbol size (line weight).
    – Midavalo
    Mar 10, 2016 at 9:48
  • Thank you, I tried it, but unfortunately it did not work out. When I load my symbology template layer, the lines have a strenth of 2, but when applying this symbology to my Input, the lineweight set to 1 again. Any other idea?
    – the_chimp
    Mar 10, 2016 at 10:39
  • When I run the ApplySymbologyFromLayer tool manually in ArcGIS, the lineweight is also applied. Maybe the Problem is that I use it in the python script, where I, after the ApplySymbologyFromLayer function I modify the class break values (as in my first post, this first changed also the colors, maybe now it is still changing lineweight).
    – the_chimp
    Mar 10, 2016 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.