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?
-
1What version of ArcGIS desktop are you using?Devdatta Tengshe– Devdatta Tengshe2013年10月01日 11:34:27 +00:00Commented Oct 1, 2013 at 11:34
2 Answers 2
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])
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])