qgis – Making Marker Label Rotate with Marker in QGIS

labelingmarkersqgisrotate

I have an arrow marker (svg) that I use for photo location and direction on maps.

Under the arrow I want a label that is the number of the photo (photos by number are located elsewhere in a report). The number will have a white circle background. I can achieve this using Offset from Point and defining the quadrant and y value. Works for the arrow always pointing north. 🙂

The problem is that I cannot identify how to make the label rotate with the arrow marker/symbol such that it is always "under" the arrow (yet still oriented correctly as text).

enter image description here

As you can see, the arrow for image 2 points east but the label has not changed its position to still be inside the chevron.

"Use data defined properties for rotation with the same field on both marker and label"

Any online guide that explains this process?

I don't even understand the terms you are using.

Subsequent to the answer with examples:

After inputing the parameters you suggested (cutting and pasting your coding) it gave the message "Result of the expression is not a geometry."

enter image description here

And the result was that the circle and number disappear altogether.

enter image description here

project (make_point ($x,$y), 1, radians(45)) version below

enter image description here

Best Answer

Use Geometry Generator for label placement with Offset from point and use this expression (see below for variants A)if the solution should fit different map scales and B) if the labels itself should also be rotated):

project (
    make_point ($x,$y),
    2500,  -- change the distance to fit your needs
    -radians(180 - "rotation") -- rotation is the name of the attribute containing rotation values
)

The red dot indicates the actual point geometry; the value of 2500 in the above expression is the distance from this point: enter image description here

If you zoom in and out, a fixed distance is not ideal as the label moves too far away from or comes too close to the arrow. To fit different scales, use a small distance value and multiply it with the variable @map_scale:

project (
    make_point ($x,$y),
    0.016 *  @map_scale,
    -radians(180-rotation)
)

enter image description here

enter image description here

If you want to rotate the labels as well, go down to Data defined and set a data driven override for Rotation, where you just set the attribute that contains the rotation angle (the same you used for the arrows).

enter image description here

Related Question