Points layer distance from the start of line layer in QGIS

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.  • Where is the "start of the road layer"? Is the road layer just one road, and the start is the first vertex on it? Apr 19 '18 at 16:16
• Star of road layer is direction and first vertex. I have multiple roads with unique code field and similarly multiple points along these roads. Apr 19 '18 at 16:22
• So you want the straight line distance from points with some code=i to the first vertex (which for your example might be the bottom left point of the line) of the road with code=i ? All roads are a simple single linestring (not complex features with branches)? Apr 19 '18 at 17:38
• first of all thanks for the very helpful manual. I would like to take up the topic again to determine the m-value. Is it possible to calculate the corresponding m-values of the points using a routed and calibrated line? The expression "m(\$geometry)" can be used to determine the m-values. Unfortunately, I couldn't include this in the calculation. Further information can be found at: gis.stackexchange.com/questions/224665/… Thank you in advance! Feb 1 '19 at 11:35
• Hi. Answers are ment to be answers not questions. Please post it as a new question.
– Mat
Feb 1 '19 at 11:59

QGIS 2.18 has a new function line_locate_point().

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 1). It will return the distance along the line, something like below. Update

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.

Update2

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: Update3