We’ve all been there, an awesome map and you need to label the features based on the attribution of a feature…..
….only you just realised that the feature is classified and you only want to show the values associated with one of the classifications, so what do you do?
The usual answer to the question from a lot of my colleagues is convert the labels to annotation which, in my opinion, is a poor solution as text easily gets lost or you find you have to re-allocate 100+ labels by hand…..and then you find that not all the labels are the correct size, sure, they SAY they are but you can see that they aren’t!
I had this problem a few days ago and instead of using the route above, I decided to brave it and open the VBscript options within the “label expressions” options and write a little code to solve this problem. I thought you might find it useful too.
Let us consider the scenario where we have an undersea cable which we have marked with Kilometre Points (KPs) and for each of these there is a reason why the KP has been added and we ONLY want to show the whole numbers, where there is a KP marker (Not any of the other reasons).
The Attribute table may look a little like this:
In this example we would only want to show the numbers 15, 16, 17, 18, 19 & 20 on the map and ignore all the other values in the KP field.
First open the feature properties and go to the “label” tab, in the “Text String Label Field” select “KP” and then click on the “Expression” button.
Select the Advanced option (on the right) and ensure that you are using the VBscript parser (bottom of the window).
This is the script I used – feel free to update me on how this can be improved, I am no programmer (Unless it is Sinclair Basic!!):
Function FindLabel ([Reason], [KP]) If [Reason]="KP" Then FindLabel = [KP] End If End Function
Of course, this can be adapted to suit your needs, for example you could add another field to check muliple values or add some additional text to the output by using something like FindLabel = “THIS IS AN EXAMPLE “&[KP] instead of the FindLabel = [KP] to get it to produce your own text before each label.
I only post this as a building block though it is something I have never seen in any of the training or help pages, so if you have any further tricks like this for labelling text I would be happy to add it & share it!! Nick D