In QGIS, is there a way to "pin" labels and features from a lower zoom level so that they appear higher up?

For instance, considering a map of the US, it would be impossibly cluttered to show every local road and town on a national scale. What if for instance, I wanted to take a specific road and the cities along it, and pin their labels such that these few features appeared even on a national scale? For example, could I take the section of I90 that runs through South Dakota and ensure that it and each town along the road appeared at all zoom levels?

I'm using QuickMapServices for base maps, but suspect this is something that can be done more generally if at all.


Basemaps obtained through the QuickMapServices plugin are WMS (Web Map Service) layers. With a WMS layer, what you see is what you get. You don't have any control over individual labels and features.

A WFS (Web Feature Service) layer, on the other hand, allows you to access and manipulate features and labels through queries. See this page for more info on the difference between WMS and WFS layers.

In order to control individual labels, you need the data either as a vector layer, or as a WFS layer.

The national map viewer provides several WFS layers. Transportation, govunits and geonames are probably the ones you want. See QGIS Training Manual, 11.2. Lesson: Web Feature Services for instructions on adding a WFS layer.

Or you can download individual features (such as sections of I-90 in North Dakota) from Open Street Map with the QuickOSM or OSMDownloader plugin.

Here's an example of how to download and label I-90 in South Dakota using the QuickOSM plugin:

Zoom to South Dakota on your map canvas. Open QuickOSM.

Key: highway; Value: motorway; choose "Extent of the map canvas"

enter image description here

Alternatively, draw a polygon around your area of interest and use the extent of that layer instead of the extent of the canvas.

After running that query, you should have a layer of points and one of lines. Here's what the lines layer looks like: enter image description here

Important: This is a temporary layer. Temporary layers are deleted as soon as you close the project. Be sure to export it to a permanent file before proceeding. Right click on the layer name > export > save features as...

By using the Identify tool, we can see that the name of the highway is stored in a field called "tiger:name_base".

Now we can set up a rule-based label so that only the I-90 highway portions are labeled.

Open layer styling > labels. Select rule-based labels. Type in a filter expression:

"tiger:name_base" = 'I-90'

enter image description here

Type "tiger:name_base" in the text box next to "Label with".

Here's what the labels look like now:

enter image description here

One of the best features of QGIS is layer styling and labeling. You really have a lot of control over how your features are displayed and labeled. See QGIS Training Manual, 4.2. Lesson: The Label Tool for more information on customizing labels.

To add labels for towns along I-90, decide how wide an area you want to include. Buffer the I-90 highway line by that amount. Use the buffer as the extent for a QuickOSM query of cities, towns, villages etc.

  • This is amazing so far. One question about the final bit on adding towns. I got mmqgis and used it to add a buffer of a given radius around the "road" (I'm actually using a series of gpx tracks for this). I had a lot of trouble getting QuickOSM to add the towns at first until I discovered you just can't ask it to add too many at once. Even when I take it in smaller chunks though, I notice the "extents" of the path-buffer I want to query in is actually the rectangle of least area bounding the buffer whose edges are lines of longitude and latitude. – fedora Aug 25 '18 at 4:26
  • For instance, the extents exactly match a horizontal buffer, but for a diagonal buffer actually encompass everything inside the rectangle bisected by the buffer. Is there a better way to add only "places"within the boundary of the buffer, or is this the way it goes? – fedora Aug 25 '18 at 4:26
  • That's what it means by "extent of a layer." Unfortunately this plugin doesn't have the option to use a polygon as the boundary. You may want to download the data another way. – csk Aug 26 '18 at 21:59

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.