Easier Conditional Labels in QGIS

With Martin’s latest addition of conditional statements it’s now even easier to get conditional labels in QGIS. Following up on the example used in my previous post, we can simplify

substr(osm_name, 0, (clazz = 11 or clazz = 13 or clazz = 15 or clazz = 21)*-1)

to

CASE WHEN (clazz = 11 or clazz = 13 or clazz = 15 or clazz = 21) THEN osm_name END

which is much easier to read and remember.

To avoid roads from being labeled with only their road numbers, I added an additional check that the “osm_name” is longer than six characters. Thanks to Nathan’s syntax highlighting this new and powerful expression based labeling is also comfortable to use.

Conditional labels for an osm2po layer

Advertisement

One thought on “Easier Conditional Labels in QGIS

  1. It’s great ! Now I’m waiting for the same in symbols. Like :

    base symbol is symbol1
    If label1 = “mercure” so set color to blue else red
    add text”label2″ on symbol

    Something like this :)

    Now I’v to write each rules, for each cases to show each symbols. Instead of writing one conditional symbol rule.

    Using QGIS give me so much fun !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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