GIS Tips – Display Some Text Labels from Attribution and not Others – ArcGIS

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


  1. I really need to remember this, I’ve gotten things like this all the time. Ended up with other work arounds, but I will definitely use this next time.


  2. There is a page on label expressions buried in the help doc and it contains quite a few example scripts in VBScript, Python, and JScript:

    Fyi, if you didn’t have the Reason field, you could also use InStr to filter out the labels containing a decimal point:

    Function FindLabel ( [KP] )
    If Instr([KP], “.”) = 0 Then
    FindLabel = [KP]
    FindLabel = “”
    End If
    End Function

    1. Thanks Jon, you’ve obviously done this before, thanks for the update to my bodged script.
      The ESRI label expressions page is good and I heartily recommend it, though I feel that it is a little to confusing for the average user and doesn’t cover anything more complex than adding a bit of text to the end of your label.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.