2

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

0

2 Answers 2

4

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
1
  • Hi Emil , i updated my question a bit. I think i am doing this process already. I am trying to build it into a script that do the process automatically , so i will the values i might encounter from my top level layer. But will not know which values i have in my layer Commented Jun 23, 2015 at 20:46
3

Since arcpy doesn't let you customize your layers, and only load symbology from already-created layers, you'll need a library of layers for all your potential combinations of values. Then you're going to have to figure out a way to reference the correct layer file for your layer that suits your data.

Something like this perhaps. I find the min and max values in the layer's table, categorize them by factors of 100, and then apply the proper layer.

"""
Create layers with standardized names:

r"C:\GIS\layers\min100max500.lyr"
r"C:\GIS\layers\min200max500.lyr"
r"C:\GIS\layers\min300max500.lyr"
...etc etc etc

"""

#Get values from field in layer
tableValues = [r[0] for r in arcpy.da.SearchCursor (lyr, field)]

#Get max value
maxValue = max (tableValues)

#Determine max category
maxValueCategory = int (round(maxValue, -2)) + 100

#Get min value
minValue = min (tableValues)

#Determine min category
minValueCategory = int (round(minValue, -2))

##Layer path
lyrFile = r"C:\GIS\layers\min{0}max{1}.lyr".format (maxValueCategory, minValueCategory)

try:
    arcpy.ApplySymbologyFromLayer_management(lyr, lyrFile)

except:
    print "Cannot locate", lyrFile
2
  • Hi Emil thanks for your help . the library or layers that are created will this have to be done manaually ? I think maybe i am best using the symbology as it has been applied in the original way. If i restrict the symbology to only certain values then if new data is added to the source data it might not get picked up in the restricted symbolology. Even though it might not look great on the TOC , its probably the most correct Commented Jun 24, 2015 at 8:59
  • Yep, you'd have to make all the layers manually. Commented Jun 24, 2015 at 19:51

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