TL;DR: I would like to put two labels on the same line as on the picture below.

I have three layers:

  • Points: `"Point_ID""
  • Lines: `"Line_ID""
  • Label table (non-spatial): "ID", "Line_ID", "Start_point_ID", "End_point_ID", "Label"

Some of the lines are referenced twice in the Label table but with different directionality. I would like to label my lines based on the label direction in the label table, just like on the picture below.

enter image description here

My question is how could I achieve this?

I know I could duplicate the line feature and add an extra attribute based on the joined Label layer with the values like "forward", "backward" but I would like to stay with one line layer.

Is it maybe possible to use geometry generator tool in QGIS? I have the Point_ID-s if I join the Label layer. (I don't seek complete solution to my problem. I just need some guidance.)

Or is there a way more easier way I don't know about? A plugin for example?

  • 1
    Just to remark: upside down labels are not considered "best-practice" in cartography and should be avoided. I guess you have a reason to still do so.
    – Babel
    Nov 7, 2022 at 8:01
  • Yes, it is strictly for the temporary visualization of the line directionality.
    – 588chm
    Nov 7, 2022 at 8:42
  • Using arrows would bei an option
    – Babel
    Nov 7, 2022 at 8:57

2 Answers 2


Instead of single labels, use rule-based labeling and create two rules: one for the label this way, the second for the label that way.

enter image description here

For the second one, in placement tab, activate Geometry generator with this expression to change the line direction: reverse($geometry) and be sure to have checked the box Line orientation dependent postion (screenshot 1).

On the placement tab, activate Show upside-down labels by selctign always (screenshot 2).

enter image description here

enter image description here

  • 1
    Perfect! This is exactly what I was looking for. Thank you!
    – 588chm
    Nov 7, 2022 at 6:09

A way would be something like this (not tested with real data/layers):

lns.geometry, lbl.Label
FROM Label_table AS lbl
JOIN Lines_layer AS lns
ON lns.Line_ID = lbl.Line_ID
ST_StartPoint(lns.geometry) = 
    (SELECT Points.geometry from Points WHERE Points.Point_ID = lbl.Start_point_ID LIMIT 1)
ST_EndPoint(lns.geometry) = 
    (SELECT Points.geometry from Points WHERE Points.Point_ID = lbl.End_point_ID LIMIT 1)

which creates a new layer only with lines which have a label associated, aond only if labels are in the correct direction (i.e. Start_point_ID is the first point of the corresponding line, and End_point_ID the last). That should work also with polygons, BTW.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.