11

I have four fields managing the numbering of the start and end of road sections.

I created two label rules, one for the start and one for the end of the road sections.

I set the position of the labels to "parallel / on the line".

I tried to configure the position of the labels according to these expressions x(end_point ($ geometry)) and y(end_point ($ geometry)) for the end of the road sections, and a similar expression for the start of the road sections.

The problem is that the labels no longer take into account the position "on the line" and certain labels no longer appear due to their overlapping.

This tool exists in arcmap which allows you to manage the labeling from the start or the end of the road section. Is there a similar tool in QGIS? enter image description here

If not, do you have an idea for a script allowing you to configure these labels?

0

2 Answers 2

17

2020 Oct update - label placement at start/end of lines or with a given offset is now be an inbuilt feature of QGIS 3.16 ! Link shows it in action.


QGIS 3.8 to 3.14

Consider using the geometry generator option under label placement, and generate just a tiny subsection of your linestring at the beginning or end to place the label on.

First go to Labels > Placement > geometry generator and select geometry type as linestring:

enter image description here

In the expression box (red arrow in image above), to place your label at the start of the line, use

line_substring($geometry,0,1)

To place your label at the end of the line, use

reverse(line_substring(reverse($geometry),0,1))

Finally, I strongly recommend setting 'Overrun feature' (above the geometry generator setting) to a few millimetres at least.

Otherwise, play with the expression and change 1 to a larger number (the label may start drifting away from the end point though).

Result:

enter image description here


The above assumes your layer is in a projected coordinate system. If it is using a geographic coordinate system like EPSG:4326 you either need to use much smaller values or transform your geometry in the expression (or save a copy of your data in a projected coordinate system)

5
  • How did you put the label at BOTH the start and end using the geometry generator?
    – Nick_Jo
    Commented Apr 25 at 22:33
  • I hunted around and found this: " collect_geometries( expression 1, expression 2... expression n) "
    – Nick_Jo
    Commented Apr 25 at 22:35
  • 1
    @Nick_Jo: with Rule based labeling, you can add multiple Labels (with multiple always true expressions)
    – Kasper
    Commented Apr 26 at 16:42
  • @Kasper: I asked a question and got another, better in for my case, answer. gis.stackexchange.com/q/480481/205328
    – Nick_Jo
    Commented May 2 at 22:35
  • 1
    If you want the same label in 3 places for sure. Your question illustrated different labels (start/end)
    – Kasper
    Commented May 3 at 5:15
2

If you want labels after line end and before start like this: enter image description here

You can use these configs:

For the start of line:

  1. Geometry Generator -> Point/Multipoint ->

    start_point($geometry)

  2. Rotation -> Edit ->

    angle_at_vertex( geometry:=$geometry, vertex:=0) - 90

  3. General -> Mode -> Around Point

  4. General -> Quadrant -> Edit -> 3

For the end of line:

  1. Geometry Generator -> Point/Multipoint ->

    end_point($geometry)

  2. Rotation -> Edit ->

    angle_at_vertex( geometry:=$geometry, vertex:=-1) - 90

  3. General -> Mode -> Around Point

  4. General -> Quadrant -> Edit -> 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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