4

Working in QGIS 3.34.3 Prizren and have a points layer visualized as 2 blue vector field marker arrows (visualized by angles called angle rbear & lbear respectively). The grey arrow is the 3rd VFM layer and its angle is based on a heading field. All angles are measured clockwise from north (0-359).

enter image description here

The direction of arrows is fine but I want the labels to appear at the end of each arrow (only right label is shown here). Labels represent a left count and right count value. I have 2 rule based labels like this for the left & right arrows ("Count" * ("Direction" = 'Right').

What I have tried:

  • Offset from point > quadrant: no expression, just chose a quadrant. This is the closest thing to what I want but the offset distance is too small.

I want the labels at the orange line

  • Rotating the point based on heading (grey arrow), then offsetting the label (Offset X,Y) but it does not move on an angle, it just moves 50 units right enter image description here
  • Offset X,Y override: array( x($geometry) + "length" * cos("rbear"), y($geometry) + "length" * sin("rbear")) enter image description here

I think a Case Else won't work for a quadrant override because I would have to write too many statements for all the angles between 0-359 and wouldn't be able to control the precise angle of the label, only the quadrant.

I'll be exporting as a leaflet map with QGIS2Web so maybe I configure the left/right labels there instead of QGIS?

Solution

Created a rule for left labels and rule for right labels. For each, used geometry generator and used a data defined rotation based on the heading (small arrow)

(```make_point( $x+(sin(radians( "rhead" ))* 0.0007), $y+(cos(radians( "rhead" )) * 0.0007)))

Follow up question

Labels are nearly complete, but they appear too close to the points when zoomed out, and too far from the points when zoomed in. I tried setting scale dependent visibilities and a scale range, but these don't affect how far the label appears from the point at different scales.

Any ideas on how to dynamically generate the label offset based on zoom scale so that they still appear near the arrows when zoomed in (example below) enter image description here This is what I want to do

enter image description here

This is what is happening, labels appear too close to point when zoomed out

enter image description here

and too far from point when zoomed in

Update

Used expression to prevent label from "moving further/closer" to the arrows when zooming in & out:

with_variable('reference_scale', 1800,
    make_point(
      $x + (sin(radians("rhead")) * (0.0007 * @map_scale / @reference_scale)),
      $y + (cos(radians("rhead")) * (0.0007 * @map_scale / @reference_scale))
    )
)

1 Answer 1

4

Based on your setup i would think there is two options. Each one has advantages and disadvantages. If you use a symbol marker you can just set it and forget it. The downside is that it does not remove labels when zooming out, so it is not good for dynamic labels. Here is my setup for that: enter image description here enter image description here enter image description here

The (in my opinion) better method is to use actual labels, this can be accomplished by setting the label point using a formula. I used the geometry generator to generate a point based on a set distance (this could be set from a field too) and the azimuth of the point. See screenshots for details.

I then defined the rotation from the field and you get the labels where you want them. you can apply this method to your project for each of your rule based labels etc. Here is the formula I used:

make_point(
$x+(sin(radians( "Azimuth" ))* 15),
$y+(cos(radians( "Azimuth" )) * 15)
)

See screenshot.

enter image description here

2
  • The second option worked out well for me, I really appreciate your help on this, thank you sooooo much! The last thing I'm trying to figure out is how to make the labels appear dynamically based on scale. Basically the labels are rotated correctly but only appear offset from the point when zoomed to the right scale. If I zoom in too much, the labels are far from the point and vice versa. I've added pictures to the post Commented Feb 16 at 21:11
  • Solved, thank you Christian! Commented Feb 16 at 23:15

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