5

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

4

You can remove the text 'Label' from "Default Label" option in labeling dialog.

(Or use new labeling.)

There is no SQL for labels yet (but you don't need it in this case).

  • Well, that was pretty obvious solution for my immediate needs of removing the default "Label". Are there any plans for SQL based labeling in the future? And where can I find the "new labeling" you mentioned (I am using v1.6)? – RyanDalton Feb 17 '11 at 19:03
  • 'Labeling' tool is located in 'Attributes toolbar' in 1.6 (icon reads 'ABC') – underdark Feb 17 '11 at 19:27
  • I couldn't find a ticket for this feature. You might want to file an enhancement request at trac.osgeo.org/qgis – underdark Feb 17 '11 at 19:33
8

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

  • Ignore the Expression is invaild that is because I don't have those columns in layer – Nathan W Jul 20 '12 at 3:39
0

You can select the option in Labels Properties and only label 'selected features'

  • While that is a neat tool that can be used much like a "tool tip", it doesn't really work in my scenario because I don't want to label a selection set, but rather the whole data layer, just without certain characteristics. With "selected features" turned on, it will reset the labels with each change in the selection. – RyanDalton Feb 17 '11 at 19:11

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.