[GIS] Performing advanced labeling using Python in ArcMap

arcgis-10.1arcgis-desktoparcmaplabelingpython-parser

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>"
       else:   
         return "cis-1,2-Dichloroethylene  "+[cis12DCE]

How do I repeat this so I get a label that looks somthing like this:

enter image description here

Best Answer

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"
        else:
            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.

Related Question