[GIS] Showing only uppercase text as labels in QGIS

labelingqgisqgis-2.14

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

Best Answer

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:

    func("fieldName")
    
  4. Then Apply all changes. Your labels should now only contain those which are all capital letters.


Example:

Before running the function:

Before function

After running the function:

After function

Related Question