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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 1, 2013 at 11:15
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])
answered Oct 1, 2013 at 12:35
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])
answered Sep 4, 2015 at 21:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.