I've got a Linestrings layer.
Each Linestring has among other fields, these ones:
id ENTRY EXIT
1 S1 E2
2 S1 E3
3 S1 E3
4 S1 E3
5 S1 E3
6 S1 E1
7 S1 E3
8 S1 E2
9 S2 E5
10 S2 E3
11 S1 E1
12 S1 E1
13 S3 E4
14 S1 E2
15 S1 E1
I want to show for each Linestring, the ENTRY value as a label at the beginning of the Linestring and the EXIT value at the ending.
Something like this (Only the red labels):
One approach would be to create a new points layer with the beggining and ending points of each Linestring and add the data of the Linestring to each point and after that just show the labels…but, is there a way of achieving what I want using only the existing Linestring layer?
Best Answer
You can do this with two "Rule-based Labelling" labels, with no filters. This lets you put multiple labels on a feature. The first rule labels the feature with the attribute you want at the start, the second rule with the end attribute. Initially your labels will appear in the centre of the line, so we need to fix that.
Do that with "data defined" expressions for the position. Use the drop-down and hit "Edit...". For the label at the start, use
x_at(0)
andy_at(0)
for the position expressions. For the end label, usex_at(-1)
andy_at(-1)
. End result is: