[GIS] Applying symbology to a layer with python, How to only have symbology in TOC that the sub layer has

arcgis-10.1arcpypythonsymbology

i am trying to apply a symbology to multiply layers that i have created from one feature class.

The original feature class is used to create several sub layers see
layer loop

this involves using arcpy.MakeFeatureLayer_management

Before using arcpy.SaveToLayerFile_management

i would like to apply some symbology to the layers that have been created. I thought if i took the original feature class and applied some the desired symbology and then saved this as a layer file. This could be used when using the Apply Symbology From Layer

The layers were made and then the symbology was applied.

But when drag the layers into ARC MAP , they all have the identicaly symbology showing in the TOC.

The actually polygons are coloured up correctly.

Example _ Original feature class symbology

1-100 = ORANGE

101 – 200 = RED

201- 300 = BLUE

301 – 400 = GREEN

401 -500 = PURPLE

Created layer value

10

200

300

In the TOC the symbology contains all of the items within the the template

How the layer is showing in the TOC

1-100 = ORANGE

101 – 200 = RED

201- 300 = BLUE

301 – 400 = GREEN

401 -500 = PURPLE

Desired Output

1-100 = ORANGE

101 – 200 = RED

201- 300 = BLUE

Is it for the TOC to show the desired output. My worry is that someone might look at the symbology and assume there are data points. When actually none exist

Best Answer

Since you know exactly what you want your new symbolization to be, I would suggest saving a layer file with that symbolization. In arcmap, add a test layer to your table of contents, and symbolize it as desired (1-100 orange, 101-200 red, 201-300 blue). Then right-click on the layer in the table of contents and 'Save As Layer File...' This lets you save the symbology in a .lyr file.

Now you can reference this layer file in your code for your final output.

for example:

lyr = "test_layer" #Layer name to apply symbology to

symbolLyr = r"C:\temp\symbology.lyr" #Layer file with desired symbology

arcpy.ApplySymbologyFromLayer_management(lyr, symbolLyr) #Apply symbology