AnsweredAssumed Answered

Using Python Labeling Expressions in ArcGIS Pro

Question asked by jgerland_Castilaw on Jan 12, 2018
Latest reply on Feb 5, 2018 by jgerland_Castilaw

Hello, I am definitely a novice when it comes to scripting. I know there is a way to do what I am asking, but I lack the skills to do it right now.


I have a wetlands shapefile that has many wetland features in it that need to be labeled according to their attributes. What I mean by this is: 

All forested wetland features need to be labeled a dark green Arial 10 pt. bold with a 1 pt. white halo

All riverine features need to be labeled a deep blue Arial 10 pt. bold with 1 pt. white halo

All ponds need to be labeled a light blue Arial 10 pt. bold with 1 pt. white halo



The shapefile has a field in the attribute table called "ATTRIBUTE" which contains NWI code for what type of wetland the feature is.

So, forested wetland's "ATTRIBUTE" field starts with the letters "PFO"

Riverine features' "ATTRIBUTE" field starts with the letter "R"

Ponds' "ATTRIBUTE" field starts with "PUB"

and etc...


The actual NWI code in the "ATTRIBUTE" field is longer, but the first three letters or so is what distinguishes a forested wetland from a scrub-shrub wetland 

ex. PFO1C is a forested wetland while PSS1C is a scrub-shrub wetland. So, I just need the script to use a "begins with" type distinguishment.


I have used SQL to define classes in the Label Manager and then manually modified the text symbol for each class, but what would really help is to be able to have a python script saved that can do the symbols and the classifying in one step so-to-speak.


Not sure if anyone needs this, but the SQL expression I have been using in each label class is simply:


and I just substitute "PFO" for whatever I need for that labeling class.


I attached an image of what I want to do. I hope for the same result as this (which I did by creating label classes and using the simple SQL expression above in each class and then manually modifying the symbols in each class) but just in a single python script. Could anybody help me get started? I just don't understand how to structure the script or use appropriate syntax.


Thanks so much!An example of the type of labeling I would like to automate.