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.
alright. Check this one (Python)
(([RE1]+'/'+[RE2]+'/'+[RE3]).rstrip('/ / ')).rstrip('/')
or
([RE1]+'/'+[RE2]+'/'+[RE3]).replace('/ /','')
Could you use Python Language?
Could you check if rstrip('/') function works for you?
([RE1]+'/'+[RE2]+'/'+[RE3]).rstrip('/')
Hi Jayanta,
Thanks for your comment. I just tried that, got an error message, and ($feature.RE1 +"/"+$feature.RE2+"/"+ $feature.RE3).rstrip('/')
For both I got the message
Thank you.
Copy-paste my script if you have changed the language to Python.
No need to use $feature. Also call the fields from the Fields list.
Please share screenshot of your label expression as well.
Thank you, I hadn't changed language to Python, but still did not work
alright. Check this one (Python)
(([RE1]+'/'+[RE2]+'/'+[RE3]).rstrip('/ / ')).rstrip('/')
or
([RE1]+'/'+[RE2]+'/'+[RE3]).replace('/ /','')
Thank you so much you legend, the first one was successful.
Not the most elegant solution, but you could employ the removeEmpty parameter from Split (Arcade). I.e. concatenate the values using Concatenate, split the new string with the removeEmpty parameter set and then concatenate again to get your label.
I use something like this in the advanced expression of Python:
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])
Sorry, I just tried it and realised it doesn't work with "/". It still has the unwanted extra //. Curious! The same code with ", " instead works fine for me. I don't know why, sorry!
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])