Recent labelling improvements in QGIS master

If you’re not like me and don’t keep a constant eye over at QGIS development change log (be careful – it’s addictive!), then you’re probably not aware of a bunch of labelling improvements which recently landed in QGIS master version. I’ve been working recently on a large project which involves a lot (>300) of atlas map outputs, and due to the size of this project it’s not feasible to manually tweak placements of labels. So, I’ve been totally at the mercy of QGIS’ labelling engine for automatic label placements. Generally it’s quite good but there were a few things missing which would help this project. Fortunately, due to the open-source nature of QGIS, I’ve been able to dig in and enhance the label engine to handle these requirements (insert rhetoric about beauty of open source here!). Let’s take a look at them one-by-one:

Data defined quadrant in “Around Point” placement mode

First up, it’s now possible to specify a data defined quadrant when a point label is set to the Around Point placement mode. In the past, you had a choice of either Around Point mode, in which QGIS automatically places labels around point features in order to maximise the number of labels shown, or the Offset from Point mode, in which all labels are placed at a specified position relative to the points (eg top-left). In Offset from Point mode you could use data defined properties to force labels for a feature to be placed at a specific relative position by binding the quadrant to a field in your data. This allowed you to manually tweak the placement for individual labels, but at the cost of every other label being forced to the same relative position. Now, you’ve also got the option to data define the relative position when in Around Point mode, so that the rest of the labels will fall back to being automatically placed. Here’s a quick example – I’ll start with a layer with labels in Around Point mode:

Around Point placement mode

Around Point placement mode

You can see that some labels are sitting to the top right of the points, others to the bottom right, and some in the top middle, in order to fit all the labels for these points. With this new option, I can setup a data defined quadrant for the labels, and then force the ‘Tottenham’ label (top left of the map) to display below and to the left of the point:

Setting a data-defined quadrant

Setting a data-defined quadrant

Here’s what the result looks like:

Manually setting the quadrant for the Tottenham label

Manually setting the quadrant for the Tottenham label

The majority of the labels are still auto-placed, but Tottenham is now force to the lower left corner.

Data defined label priority

Another often-requested feature which landed recently is the ability to set the priority for individual labels. QGIS has long had the ability to set the priority for an entire labelling layer, but you couldn’t control the priority of features within a layer. That would lead to situations like that shown below, where the most important central station (the green point) hasn’t been labelled:

What... no label for the largest station in Melbourne?

What… no label for the largest station in Melbourne?

By setting a data defined priority for labels, I can set the priority either via values manually entered in a field or by taking advantage of an existing “number of passengers” field present in my data. End result is that this central station is now prioritised over any others:

Much better! (in case you're wondering... I've manually forced some other non-optimal placement settings for illustrative purposes!)

Much better! (in case you’re wondering… I’ve manually forced some other non-optimal placement settings for illustrative purposes!)

Obstacle only layers

The third new labelling feature is the option for “Obstacle only” layers. What this option does is allow a non-labelled layer to act as an obstacle for the labels in other layers, so they will be discouraged from drawing labels over the features in the obstacle layer. Again, it’s best demonstrated with an example. Here’s my stations layer with labels placed automatically – you can see that some labels are placed right over the features in the rail lines layer:

Labels over rail lines...

Labels over rail lines…

Now, let’s set the rail lines layer to act as an obstacle for other labels:

... setting the layer as an obstacle...

… setting the layer as an obstacle…

The result is that labels will be placed so that they don’t cover the rail lines anymore! (Unless there’s no other choice). Much nicer.

No more clashing labels!

No more clashing labels!

Control over how polygons act as obstacles for labels

This change is something I’m really pleased about. It’s only applicable for certain situations, but when it works the improvements are dramatic.

Let’s start with my labelled stations map, this time with an administrative boundary layer in the background:

Stations with administrative boundaries

Stations with administrative boundaries

Notice anything wrong with this map? If you’re like me, you won’t be able to look past those labels which cross over the admin borders. Yuck. What’s happening here is that although my administrative regions layer is set to discourage labels being placed over features, there’s actually nowhere that labels can possibly be placed which will avoid this. The admin layer covers the entire map, so regardless of where the labels are placed they will always cover an administrative polygon feature. This is where the new option to control how polygon layers act as obstacles comes to the rescue:

...change a quick setting...

…change a quick setting…

Now, I can set the administrative layer to only avoid placing labels over feature’s boundaries! I don’t care that they’ll still be placed inside the features (since we have no choice!), but I don’t want them sitting on top of these boundaries. The result is a big improvement:

Much better!

Much better!

Now, QGIS has avoided placing labels over the boundaries between regions. Better auto-placement of labels like this means much less time required manually tweaking their positioning, and that’s always a good thing!

Draw only labels which fit inside a polygon

The last change is fairly self explanatory, so no nice screenshots here. QGIS now has the ability to prevent drawing labels which are too large to fit inside their corresponding polygon features. Again, in certain circumstances this can make a huge cartographic improvement to your map.

So there you go. Lots of new labelling goodies to look forward to when QGIS 2.12 rolls around.

 

Tagged , , , , ,

10 thoughts on “Recent labelling improvements in QGIS master

  1. Tom Lennon says:

    Hi Again Nyall:
    I don’t know if this is the right place to make suggestions but I have a good one to make concerning labels.
    This would involve creating a new class layer (say it’s called text).
    This layer would be a line class.
    It would include the paths to all the layers in the legend as well as their legend names and level number.
    It would be created by the normal label process for all the layers and would also include all the font and placement information for those layers.
    The difference is it will also include a copy of a portion of the line that is being labeled.
    If the layer being texted is a point layer it would include the point and a line following the labeling rule (horizontal, angled, centered, above, below, quadrant etc). There would be a line the length of the text and in position to the text included.
    If the layer being texted is polygon it would include a line following the labeling rule (horizontal, angled, area following, curved, centered above, below, etc.)

    All the lines would be long enough to cover the length of the label and would have the following attributes:
    string being texted
    font
    font size
    label attribute (above, on, below,centered, rotated.
    Item ID number
    Layer Path (ref to contents table in the layer)
    Layer type

    The text layer lines and points are shown very faintly and can be turned off.
    Once the text layer is created, all regular layers have the label attribute turned off.
    At this time is should be possible to edit the text layer by touching the text and dragging, deleting, rotating rewording, etc.
    Moving the text moves the line associated to it.
    Text can be added by activating the proper layer and selecting the feature to get texted.
    All of this would create a permanent text layer which has spacial ordinates, and lines associated to every text.
    This layer can be depended on to print all the text as shown on screen every time.
    It can also be processed against a grid or graticule layer and text indexes can be made giving the wording along with the map location of the feature.
    All of this is similar to ARC’s annotation layer but improves on it by including the source path and allows editing.

    What do you thing?
    Tom

  2. Hello Nyall, I am so glad, that label engine in QGIS is still improving as I consider it to be only partialy usefull for jobs I do. I work in small municipality, producing few different maps every day for last 15 years or so. At my type of work, I would REALLY need option to pick one or more labels and move them freely to better position as they often cover underlying items. Few years ago we were still using ancient Arcview 3.x, which spoiled us with that option and even allowed us to label just selected items with cliking on them – not to mention we were able to label just visible or selected entities without worrying about adding extra fields, point themes etc.

    I understand, that data driven label engine is solution for complex, repetitive work of your kind, but a lot of us are still using GIS for producing maps in more manual ways. Maybe you wizzards will some day find solution for our needs too … Best regards! Goran

  3. maat says:

    Thanks for your input into QGIS! 🙂

  4. Great new feature Nyall. I’ve just been playing with the “Discourage other labels from covering feature in this layer” and noticed it’s really slow when the using country polygons as the obstacle layer for the labels. Do you think there is a potential optimisation for the feature as this is a real usability issue? I have raised a ticket with example project demos what I’m talking about:

    http://hub.qgis.org/issues/13556

  5. Stu Smith says:

    Hi, I just upgraded QGIS to 2.12, and the first map I produced included the data defined quadrant labels. The client is very happy. Bravo! Thanks.

  6. Magdalena says:

    I’m using QGis since 3 years and the labelling is still a big issue for me and my work. I totally support Goran an his wish to select an item by clicking and being able to move it freely. That would be enormous helpful. I hope it comes up in one of the next releases!

  7. Phil says:

    Thank you for the tutorial. How did you achieve the hatching pattern of the border in your last picture for example?

  8. Calvin Koh says:

    Nyall, great work by you in recent years. Thank you.

    I’m trying my hand in cartography and your blogs come very handy. Can you please point me how or where I can do the kind of cross-hatch that you have done in the administrative boundaries? Just couldn’t get it right, due to directional change of vector lines. Or am I making something wrong. Thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *