Monday, 5 December 2016

arcmap - Labeling using different expression if attribute is null using ArcGIS for Desktop?


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


+" "+

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?




Answer



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])

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...