Select to view content in your preferred language

How to set the symbology categories using arcpy

8840
5
05-16-2016 08:26 PM
PeterBirksmith
Deactivated User

Hi there

I would like to learn how to modify/add categories within Symbology programmatically in arcpy.

I have created a Featurelayer from a shapefile.  Now I want to set the available categories

Is this possible and if so what is the code necessary to perform this function.

Cheers

Peter

Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

see arcpy.mapping ... for example

EDIT  the direct links didn't work so I will give references to the actual classes

in the arcpy mapping classes section Introduction to arcpy.mapping—Help | ArcGIS for Desktop

UniqueValuesSymbology

GraduatedColorsSymbology

GraduatedSymbolsSymbology

The code samples will get you started

PeterBirksmith
Deactivated User

Hi Dan

Seems that I can't get the links to work but you've given me the functions I need to use so that's the important point

Cheers

Peter

0 Kudos
DanPatterson_Retired
MVP Emeritus

Yes Peter, sometimes this happens and I still can't get them to work, but they are in the arcpy.mapping section under Classes

0 Kudos
PeterBirksmith
Deactivated User

Hi Dan

Thanks again

I've tried the snippet of code however, I think I need to understand a bit more about symbologyType and where it captures this attribute from within an mxd.

would you mind if I provided you the mxd as it's created from BOM shapefiles which produces the layers.

When I run the code SymbologyType comes back as 'OTHER'

I'm obviously missing something.

print lyr.symbologyType

Returns 'OTHER'

if lyr.symbologyType == "UNIQUE_VALUES":
  lyr.symbology.valueField = "SUB_REGION"
  lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()

Cheers

Peter

0 Kudos
DanPatterson_Retired
MVP Emeritus

well OTHER means .... A string that represents an unsupported layer symbology class.

So what is your symbology class, there is only the list in the layer class

What is the layer? a featureclass?

You are running it from the current project as follows

import arcpy

mxd = arcpy.mapping.MapDocument("current")           # run from within a currently open project

lyr = arcpy.mapping.ListLayers(mxd, "Population")[0]    # this is a layer(s) called Population within the project [0] means get the 1st

if lyr.symbologyType == "UNIQUE_VALUES":             # it then checks to see if this is the symbology type

    lyr.symbology.valueField = "SUB_REGION"            # if it is, use a specific field in the layer's table

etc etc etc