[GIS] How to label features in QGIS using SQL statement

labelingqgissql

In QGIS, I can't seem to find a way to define the features that I want to label using a SQL query? Is this possible?

For example, I downloaded the OSM Natural shapefiles, and a lot of those features have no values in their "name" field. I would like to display all features, but only label those features where NAME <> "". The same concept could be applied to roads, where TYPE = "Motorway".

In the image below, I want all polygons visible, but don't want to label the 3 polys on the right.

enter image description here

Best Answer

You can now label features using an expression in version 1.8, something like this:

CASE WHEN NOT "NAME" IS NULL THEN "Name" END

or

CASE WHEN "TYPE" = 'Motorway' THEN "Name" END

Expression labels

Related Question