Using QGIS 2.14 and see there is now rule based labelling. I wish to show labels of towns that have capital letters (eg CRAWLEY) and not show the labels of towns with lowercase letters (eg Faygate)

The attribute table does not distinguish the different towns apart from their name. Is there a way of doing this ?

enter image description here


You don't really need rule-based styling for this.

  1. Select the Show labels for this layer option (or rule-based if you prefer) and click the Expression icon and go to the Function Editor as shown below.

    Function editor

  2. Create a new file (or edit an existing one) and enter the following:

    from qgis.core import *
    from qgis.gui import *
    @qgsfunction(args='auto', group='Custom')
    def func(value, feature, parent):
        if value.isupper():
            return value
  3. Click Load then go to the Expression tab and type the following:

  4. Then Apply all changes. Your labels should now only contain those which are all capital letters.


Before running the function:

Before function

After running the function:

After function

  • 8
    Instead of using a custom python function here you could also use the inbuilt expression "fieldName"=upper("fieldName") – ndawson Jan 19 '17 at 23:40
  • 3
    @ndawson - Well that's a very handy function, thank you! Although your expression only returns a boolean, you could instead use if("fieldName" = upper("fieldName"), "fieldName", ''). Either way, I think you should post it as an answer ;) – Joseph Jan 20 '17 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.