[GIS] Conditional Formatting in Label Expressions

arcgis-10.2arcgis-desktoplabelingvbscript

I need help with the syntax with my label expression. I have a specific set of parameters I need to display but I need to change only one attribute to label as something else.

I have AC pipeline that I need to label as NM. How do I get everything else to label but have anything that equals AC change to NM?

A quick work around for me was to duplicate the layer and do a Definition Query and do a simple label expression. My other layer excluded my AC mains and labeled them normally. I know there is a way to build a more complex syntax to complete this task without having to duplicate layers and create Definition queries. Here is the VBScript I have currently.

I am assuming is it would be an if then else statement…not sure how to actually write it correctly though.

enter image description here

Best Answer

What I think you really need is to use label classes. More info is available in the help documentation at http://resources.arcgis.com/en/help/main/10.2/index.html#//00s80000000v000000

Basically though, what you would be doing is creating different classes of labels that you can label differently, just like you can classify your symbology so different features draw differently within the same layer. The easiest way to work with label classes is if you already have them classified for symbology, to just go to the labels tab of layer properties and under method tell it to define classes of features and then use the button Get Symbol Classes. Otherwise, follow those same steps except don't click the get symbol classes button, but instead use the add button and the SQL Query buttons to add classes as necessary. Truth be told though, to work with labels easiest, I would recommend opening up the label toolbar and using the label manager (available from that toolbar).

If you use label classes, you can set it so features that meet your criteria ex:[FIELD] = "AC" are labeled differently than the rest of the features.

Additionally, I think if you change the label expression parser to Python, you should be able to simply use the .replace() method, depending on how your data is set up to replace the AC with NM. For example, the label expression might be something similar to str([Diameter]) + " " + str([Material]).replace('AC','NM') + " " + str([Date])

Related Question