Select to view content in your preferred language

How to group values after Unique symbology classification in arcpy?

1975
6
09-30-2016 12:44 PM
ManjariGoyal
Regular Contributor

I am trying to group values through arcpy. So, I would like to group all approved together and all reject together. But I am not sure how to do it through Python script. Below is the part of the script:

arcpy.MakeFeatureLayer_management(FC3, r"C:\Users\Documents\NGN\Regions\MW_Decision.lyr")
layer3 = arcpy.mapping.Layer(r"C:\Users\Documents\NGN\Regions\MW_Decision.lyr")
Sym_layer3 = r"C:\Users\Documents\NGN\Symbology layer new\MW_Decision.lyr"
arcpy.ApplySymbologyFromLayer_management (layer3, Sym_layer3)
arcpy.mapping.AddLayer(df, layer3, "AUTO_ARRANGE")
lyr3 = arcpy.mapping.ListLayers(mxd, "", df)[0]
lyr3.visible = False
lyr3.name = "MW_Decision"

Any help is appreciated.

Tags (1)
0 Kudos
6 Replies
AndyOmmen
Esri Contributor

Hi Manjari,

In the Layer properties under the Symbology tab, select all the approved symbols using the Shift key, right click on the selected symbol rows and select Group Values. This will condense all selected symbols into one symbol set which you can modify. You will need to do the same for the rejected symbols as well. Save this symbol configuration with your Sym_layer3 and it will get applied to the MW_Decision.lyr when you run your script. I hope this helps.

Thanks

Andy

0 Kudos
ManjariGoyal
Regular Contributor

Hi Andy,

I tried this way but it didn't work. It doesn't group the values. But one thing I noticed that if I import the symbology layer from the symbology tab it works (it groups the values). So, I am not sure why it doesn't group the values from Arcpy.

0 Kudos
ManjariGoyal
Regular Contributor

Dan, I have tried it but it doesn't work with Reresh TOC. Below is the complete script.

import arcpy
from arcpy import env
import arcpy.mapping

# Set environment settings
env.workspace = "C:\Users\Documents\NGN\Regions"
arcpy.env.overwriteOutput = True

#define projection
Prjfile = r"C:\Users\Documents\NGN\Regions\WGS1984.prj"
spRef = arcpy.SpatialReference(Prjfile)

#Local Variables
FC3 = r"C:\Users\Documents\NGN\Regions\South_DO.gdb\MW_Decision"
FC4 = r"C:\Users\Documents\NGN\Regions\South_DO.gdb\RF_Decision"


mxd = arcpy.mapping.MapDocument(r"C:\Users\Documents\NGN\DO Maps\Demo_South.mxd")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

arcpy.MakeFeatureLayer_management(FC4, r"C:\Users\Documents\NGN\Regions\RF_Decision.lyr")
layer4 = arcpy.mapping.Layer(r"C:\Users\Documents\NGN\Regions\RF_Decision.lyr")
Sym_layer4 = r"C:\Users\Documents\NGN\Symbology layer new\RF_Decision.lyr"
arcpy.ApplySymbologyFromLayer_management (layer4, Sym_layer4)
arcpy.mapping.AddLayer(df, layer4, "TOP")
lyr4 = arcpy.mapping.ListLayers(mxd, "", df)[0]
lyr4.visible = False
lyr4.name = "RF_Decision"

arcpy.MakeFeatureLayer_management(FC3, r"C:\Users\Documents\NGN\Regions\MW_Decision.lyr")
layer3 = arcpy.mapping.Layer(r"C:\Users\Documents\NGN\Regions\MW_Decision.lyr")
Sym_layer3 = r"C:\Users\Documents\NGN\Symbology layer new\MW_Decision.lyr"
arcpy.ApplySymbologyFromLayer_management (layer3, Sym_layer3)
arcpy.mapping.AddLayer(df, layer3, "TOP")
lyr3 = arcpy.mapping.ListLayers(mxd, "", df)[0]
lyr3.visible = False
lyr3.name = "MW_Decision"

mxd.saveACopy(r"C:\Users\Documents\NGN\DO Maps\South.mxd")

arcpy.RefreshActiveView()
arcpy.RefreshTOC()
del mxd,df

print "save South mxd"

0 Kudos
DanPatterson_Retired
MVP Emeritus

not clear as to why the refresh is being done after the save?

0 Kudos
ManjariGoyal
Regular Contributor

I have tried before save and after save it doesn't work. I don't think it has anything to do with refresh as my other layer RF Decision shows correct symbology.

0 Kudos