Hello. My too long labels take up too much space in regard to the small counties polygons.
I want to remove first two and the last two characters from each single label.
Currently the labels on the map look like this:
PL1607000
PL1816000
LV801200
LT029900
EE700000
etc.
Because in each single label the first two characters are two-letter country code, and the last two characters always two zeros, to make map more clean I want my labels like this:
16070
18160
8012
0299
7000
etc.
I use Maplex Label Engine. My label field is CTYCode, What expression should I type in Label expression dialog box?
Is it possible to also make stacked labels from this labels? I want to the first two characters were at the top, and the rest at the bottom. Like this:
16
070
18
160
80
12
02
99
70
00
etc.
If you want help me please add here two different expressions. With and without stacking labels, I do not know about programming at all and I would not know how to change the expression
Greg
Solved! Go to Solution.
Go in to the expression editor, turn on advanced expressions, set the parser to Python, put this as the expression for stacking:
def FindLabel ( [CTYCode] 😞
return "%s\r\n%s" % ([CTYCode][2:4], [CTYCode][4:-2])
And without stacking:
def FindLabel ( [CTYCode] 😞
return ([CTYCode][2:-2])
The best things to read up on would be string substitution (the %s stuff), slicing and indexing (the [2:4], [4:-2], etc. stuff) in Python.
Go in to the expression editor, turn on advanced expressions, set the parser to Python, put this as the expression for stacking:
def FindLabel ( [CTYCode] 😞
return "%s\r\n%s" % ([CTYCode][2:4], [CTYCode][4:-2])
And without stacking:
def FindLabel ( [CTYCode] 😞
return ([CTYCode][2:-2])
The best things to read up on would be string substitution (the %s stuff), slicing and indexing (the [2:4], [4:-2], etc. stuff) in Python.
Thank you for help!
For future reference... if you don't know the length of the object to slice... but you know that you want to slice of 2, but be careful, you may not get what you want
a = 'PL1607000'
(a[2:])[:-2]
'16070'
a = 'PL1'
(a[2:])[:-2]
''