4

I can get polyline labels to appear parallel to the line but I'd really like to have them off the end of the line, not on the line. Is there a way of doing this with QGIS?

enter image description here

7

Firstly, go on the Layer Properties > Labels > Placement window.

Then, edit the expression for both X and Y coordinates, as in the image below:

enter image description here

In the expression field, use x_at(0) or x_at(-1) for setting the label at the start or at end of the features, respectively (do the same for the Y coordinate):

enter image description here

Finally, click on the Apply button and enjoy!


EDIT

If you see that some option has been overridden, you will still be able to set the desired output if you follow these two last steps (see the image below):

3) Edit the "Rotation" parameter in the same way as before, but use this expression:

90 + line_interpolate_angle( $geometry, 0)

4) Go again to the step 2 (only step 2, only for the X coordinate!) and edit the expression by adding an "offset" to your end point (it will depend on the measurement units). For example, if I set this expression:

$x_at( -1) + 5

I will obtain the result you see in the image (I think as expected).

enter image description here

  • Thank you for this brilliant tip. Is there a similar expression to set the orientation of the label? With these expressions I get all the labels horizontal, but I really want them parallel to the polylines. Note: in the first section of the Placement tab which is titled Placement I have the Parallel radio button checked but this seems to be overridden by the data defined values. Thanks. (I'm using 2.12 Lyon. It may be this has been changed in later versions) – simonc8 Feb 13 '17 at 20:20
  • @simonc8 I edited my answer, now it should work. If it works also for you, please remember to accept my answer because it could be useful in the future for other users! =) – mgri Feb 13 '17 at 21:32
  • Thanks, @ndawson! It's a pleasure receiving your feedback =). However, I think I will edit my answer soon for a better explanation of the solution. At this moment, it's a bit difficult to clearly understand it. – mgri Feb 13 '17 at 22:02
  • 1
    @mgri Thanks for the additional functions - I had to update my QGIS to find the line_interpolate_angle function. However, I think the equation for rotation should be 90 - line_interpolation_angle($geometry,0) because the label angle increases anticlockwise while the line geometry angle increases clockwise. I am also experimenting with making the offsets more sophisticated to be applicable for lines at any orientation. This will involve a calculation using $scale, and also sin and cos of the line_interpolation_angle. I'll add a post when I've got it solved. – simonc8 Feb 14 '17 at 18:50
  • 1
    Ok, I got it. I performed the test on the line you see in the image, so I think you need to add more rules for a general case. However, I gave you an idea! – mgri Feb 14 '17 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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