Search code examples
pythonarcgisarcmap

Python label expression in ArcGIS 10.1


ArcMap 10.1, Windows 7 64-bit Professional.

I cannot get the chloride value to label correctly. The problem is with the "if [Chloride] > 0:" expression. The label renders all values from "Chloride". When the Chloride field has a value of -99, the label expression should render the 'Cl_txt' field not the 'Chloride' field.

"Chloride" has a Long data type. "Cl_text" is text. I have tried "if long([Chloride]) > 0:". Using long, the entire label does not render for Chloride values > 0, but the -99 values render the Cl_txt value of "NR". I have also tried converting with float([Chloride]) and get same results as using float.

The strange thing is that that DTW renders fine. DTW_ft is float data type.

def FindLabel( [gisID], [DTW_ft], [dtw_txt], [feat_date], [aka_name], [Chloride], [Cl_txt]):
    L = "MISC-" + str( [gisID] ) + '\n'
    L += "DTW: "
    if  float([DTW_ft])  >  0:
        L += [DTW_ft]  + " ft"
    else:
        L += [dtw_txt]
    L += '\n'
    L += "Cl: "
    if [Chloride] > 0:
        L += [Chloride]
    else:
        L += [Cl_txt]
    L += '\n'
    L += [feat_date] 
    return L

Solution

  • Simply, not to label all-99 values with [Chloride] but with [Cl_txt] try below- I assumed [Chloride] is long and [Cl_txt] is string datatype.

    def FindLabel([Chloride], [Cl_txt]):
        if long([Chloride])==-99:
            L= [Cl_txt]
        else:
            L = str([Chloride])
        return L
    

    See image- enter image description here