Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone have a good reference for advanced/complicated labeling expressions in Arcmap? I am attempting to write a Python label expression that would involve multiple label definitions.

Here is what I am trying to do: (Using ArcMap 10.1)

I have a point shapefile representing Monitoring Wells. For each Well I have taken concentration readings for various chemicals. What I need to do is label all of these concentrations for each well and color code them based on whether or not they exceed a certain limit.

This is what I have:

     def FindLabel ([cis12DCE],[cis12DCE_Ex] ):
        if int([cis12DCE_Ex]) == 2:
         return "<clr red = '255'>"+"cis-1,2-Dichloroethylene  "+[cis12DCE]+"</clr>"
         return "cis-1,2-Dichloroethylene  "+[cis12DCE]

My question is how do I repeat this so I get a label that looks somthing like this:

enter image description here

share|improve this question
Please define what each of the fields you are referencing contain. In general, the more information you can provide about what you are trying to accomplish, the better. This may include field definitions like above, a list of attributes you want to label, and the parameters by which you need to classify them. – Get Spatial May 6 '13 at 17:34
I have multiple Chemical Fields (PCE, TCE, ect). For each Chemical field I have an exceedence field with values of 1 or 2. I need to show the Chemical name and its concentration. If the chemicals exceedence value is equal to 2 then I need it to be red. Basically I need to take the script you helped me with earlier and repeat it several times for every chemical field in my table. – ACrain May 6 '13 at 17:55

I'm running 10.0, so this is totally psuedocode and may be completely wrong, but I think the idea is plausible:

def FindLabel ([cis], [pce], [tol], [field], ...):
    # Setup the headers
    label = ""
    label += "<und><bold>GW-5</bold></und>      <und><bold>24-28'</bold></und>\n"
    # Loop through fields
    flds = [[cis], [pce], [tol]]
    for fld in flds:
        if int(fld) == 2:
            label += formatted red + "\n"
            label += formatted black + "\n"
return FindLabel

Basically this sets up the header, then loops through the input fields and builds each line. I used to do some insane several hundred lines long VBScript FindLabel functions years ago. Another thing to do to make it nice and pretty and left aligned and properly spaced like it's all actually in columns is to, before you build the label, run through each label + attribute for each record, find out how long they are, and use that to build the fixed width of the label; you base it on the width of the widest attribute/value pair and then fit everything else into it. You can also test for NULLS and if you don't want to display a empty row in the label, then just skip it. Essentially you build up the label you want by running the proper tests, then stitch it all together and return it.

share|improve this answer
Thank you. I think you understood what I was trying to say. I know it wasn't very clear. Think your approach is the right track, I will play with it tonite and see where I get. Thanks again! – ACrain May 6 '13 at 21:10

Not entirely sure what you are asking as your code example works!

If you want to create text on multiple lines then you can put a new line character in it, below is an example.

def FindLabel ( [Strahler] ):
  if int( [Strahler] ) == 2:
    message = "<clr red = '255'>"+"Strahler order 2:  </clr>" + "\n" + "next line"
    return message
    message = "Strahler (other):  "+ [Strahler] + "\n" + "<bol>bold text</bol>"
    return message

If you want to add a border then you need to set the background so go to symbol > edit symbol > advanced text

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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