7

I want to visualize direction of river's course by an arrow placed next to the river's name label. I have an idea to place the blue arrow as a text in front of my label or at the end of my label, but the problem is with the qgis label engine. Depending on vector rotation label puts along or across the vector direction. Can I check somehow if label is placed along or across the vector direction? I would prefer the solution by Expression or maybe you have any better ideas how to visualize that...

Expected result below: (I marked the river's course (which equals vector direction) with the red arrow): enter image description here

1
  • Can you please specify which version of QGIS are using?
    – Val P
    Jun 29, 2020 at 15:43

1 Answer 1

7

To solve your problem you have two different options.

Solution 1 by default option

QGIS, at least from the 3.10 (not sure about previous versions), offers the opportunity to add this arrow symbol to the label by default using one of the Labels options.

In Layout Manager > Labels in the Formatting page, active the option Line direction symbol and, here, use the arrow symbols (you can copy them from the System Character Map).

This will suit your request. But, as discussed in the comments, this solution turn off the possibility to activate the useful option Merge connected lines to avoid duplicate labels and seem to be not compatible with the Placement Curved or Horizontal.

enter image description here

Solution 2 by expression (recommended)

You can achieve the same result using an expression that calculates the direction of the line to populate your label.

This is the expression

with_variable('direction',
    angle_at_vertex ($geometry, if( num_points( $geometry) >1, num_points( $geometry)/2, 1)),
        case 
        when @direction < 179 then 'label →'
        when @direction > 180 and  @direction < 360 then '← label'
        end
)

This solution is recommended because keep active and selectable the option Merge connected lines to avoid the duplicate labels and works with all the Placement options.

The if option in the expression permits to calculate the direction on the middle of a line with several nodes and avoid to misinterpreted a line that has an irregular proceeding.

enter image description here

8
  • 1
    Thank you, I totally forgot about that option in qgis. :) Jun 30, 2020 at 5:50
  • I've noticed that enabling option "Line direction symbol" turns off an option "Merge connected lines to avoid duplicate labels" from Rendering page. Is there any way to keep that option/result on? Jun 30, 2020 at 7:01
  • I have realised. It could be a problem. Unfortunately, I can't see any solution using only the default options. If this is for you a mandatory point, a label by expression would be an alternative solution.
    – Val P
    Jun 30, 2020 at 17:40
  • 1
    I mean an expression that can calculate the direction of the line and change the label according with that. I can Tey to work on it and add to the answer as second solution.
    – Val P
    Jul 1, 2020 at 8:21
  • 1
    Answer updated. Solution 2 should solve all your problems with default options.
    – Val P
    Jul 1, 2020 at 17:47

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.