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).
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.
- 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 - Offset X,Y override:
array( x($geometry) + "length" * cos("rbear"), y($geometry) + "length" * sin("rbear"))
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) This is what I want to do
This is what is happening, labels appear too close to point when zoomed out
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))
)
)