Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
1  
What version of ArcGIS desktop are you using? –  Devdatta Tengshe Oct 1 '13 at 11:34

2 Answers 2

up vote 6 down vote accepted

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])
share|improve this answer

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])
share|improve this answer

Your Answer

 
discard

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.