Hello,
I am using ArcGIS Pro and trying to get labels in a sensible way. The layer and variables I am using to create labels can have up to five classes (Regional Ecosystems, three in the screen shot below).
I have tried [$feature.RE1 +"/"+$feature.RE2+"/"+ $feature.RE3], which gives the below result, my issue being that when there was only one RE, there are is now // after the label which obviously looks silly.
Is there a way to get the extra RE labels and / to only appear if the field is not empty?
Thank you.
Solved! Go to Solution.
Well, I was foiled by my own data! Turns out it does work when you check that fields are really None (<Null>) instead of empty! This is my failsafe expression:
def FindLabel ([RE1],[RE2],[RE3]):
a = [RE1]
b = [RE2]
c = [RE3]
return "/".join([str(i) for i in [a, b, c] if i is not None and i !=""])
var raw_re = [$feature.RE1, $feature.RE2, $feature.RE3, $feature.RE4, $feature.RE5]
var filled_re = []
for(var i in raw_re) {
if(!IsEmpty(raw_re[i])) {
Push(filled_re, raw_re[i])
}
}
return Concatenate(filled_re, "/")
IlkaIllers1 handling of None is important. Null requires special handling.
Null in the attribute table means None in python.
And None plus anything equals None
Thank you everyone, Jayanta's suggestion below was successful!
(([RE1]+'/'+[RE2]+'/'+[RE3]).rstrip('/ / ')).rstrip('/')