Our colleague has written an article. We’re sharing it here.
QGIS has a flexible callout system for labels, but sometimes the cartographic style you need is not available as a ready-made option. One example is a shelf-style callout: a leader line connects the feature to the label, then continues horizontally underneath the text.
Something like this:
The tricky part is that the horizontal section should adapt to the length of each label.
Good thing is that it can be reproduced entirely with QGIS symbology, without generating additional geometries.
For this example, imagine a point layer of iconic tourist viewpoints around the Bay of Kotor, Montenegro:
Enable labels using the name field and activate a simple line callout.
Move a few labels away from their points to make sure the callouts are working.
At this stage we have the usual QGIS result: a straight line between the point and its displaced label.
Open the callout line symbol and add a Marker Line symbol layer with Marker placement on first vertex.
Instead of using a conventional point marker, use a short line-shaped marker. Set its rotation to 90° and make sure the marker doesn’t follow the direction of the callout line. This small marker becomes our horizontal “shelf”.
Now every callout consists of two visual elements:
A fixed shelf length works only if all labels are approximately the same size. Control the marker size with a data-defined expression:
length(attribute(‘local_name’)) * 2
The longer the label text, the longer the horizontal marker becomes. The multiplier depends on the font size, map units and desired appearance, so 2 is only a starting value.
By default, the marker is centered on the callout endpoint. We need to move it sideways so that the line extends underneath the text instead.
The offset can also be data-defined:
CASE
WHEN
x(@geometry)> “auxiliary_storage_labeling_positionx”
THEN
array(
0,
(length(attribute(‘local_name’)) * 2) / 2
)
ELSE
array(
0,
-(length(attribute(‘local_name’)) * 2) / 2
)
END
The same expression used for the marker length is therefore also used to calculate half of that length for the offset. We also take into account if label is placed on the left or on the right side of the feature.
After that, every label gets its own dynamically sized shelf.
And because everything is calculated at render time, there are no auxiliary layers, generated geometries or manual line features to maintain.
The only thing left to do is to tune the values and font. In my case I changed font to monospace Courier and set the constant to 2.7.
This is a nice example of how far QGIS cartography can be pushed by combining seemingly unrelated tools: Labels, Callouts, Marker Lines, Data-defined properties, Expressions. None of these features individually provides a “shelf callout” style, but together they let us construct one.
And this is one of my favourite things about QGIS! When a particular cartographic option does not exist, there is often enough flexibility in the symbology engine to build it yourself.
We’d love to hear your thoughts. Please share your ideas in the comments on the original LinkedIn post.
NextGIS Web gives your whole team – desktop, browser, and mobile – a shared place to store, edit, and publish the data that sits on top of it.