5

I am using an expression to label features by concatenating two attributes in ArcMap. It works like this:

<attribute_1>+" "+<attribute_2>

Unfortunately when either attribute is Null the whole label is left blank. How do I change my expression so that if one attribute is Null, the other appears on its own?

1
  • 1
    What version of ArcGIS desktop are you using? Commented Oct 1, 2013 at 11:34

2 Answers 2

8

Open Properties of the layer > Labels tab. Click the Expression button. Check the Advanced check box and then copy this code into the Expression window. You will have to use your fields names instead of fields I used.

def FindLabel([Type],[Name]):
    if str([Type]) == "None" and str([NAME]) != "None":
        return [Name]
    elif str([Type]) != "None" and str([NAME]) == "None":
        return [Type]
    elif str([Type]) == "None" and str([NAME]) == "None":
        return ""
    else:
        return str([Type]) + " " + str([Name])
3

This works in ArcMap 10.3.1 for labeling Open Street Map. Different quote and not using str():

    def FindLabel([osm_name_58_en],[osm_name]):
       if ([osm_name_58_en]) != None and ([osm_name]) != None:
           return [osm_name_58_en]
       elif ([osm_name_58_en]) == None and ([osm_name]) != None:
         return [osm_name]
       elif ([osm_name_58_en]) != None and ([osm_name]) == None:
          return [osm_name_58_en]
       elif ([osm_name_58_en]) == None and ( [osm_name]) == None:
         return ""
       else:
           return ([osm_name_58_en]) + " " + ([osm_name])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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