I tried to find out and read multiple similar questions but not able to get answer to my question. I have two layers; points (various location data) and lines (roads). My aim is to calculate all points distance from the start of the road layer and populate this in points layer attribute (snapshot attached). Points are little away from the road line. I checked LRS but I did not find there. I am using QGIS 2.18.
QGIS 2.18 has a new function
Open the Field Calculator and try this expression:
line_locate_point( geometry:=geometry(get_feature('Line', 'id', '1')), point:=$geometry)
(I assumed the
id field of your first line is
It will return the distance along the line, something like below.
I noticed ongoing discussion about what distance is required for this question (i.e. straight or along the line). So I thought I would post this picture may add some clarity what this
line_locate_point() tool gives us.
To work on multiple roads, you would better to have a field (
road_id) in your point layer, to identify corresponding road.
Then the expression becomes:
According to your data, please try:
- Note the change (
'road_id') of the second input parameter for
- I noticed your attribute table of line data (
road_line) has its own
road_idfield. (It was not in my test sample. Sorry for the confusion caused.)