How do you measure distance from a line end point to a point on a separate layer in QGIS 3

distancelineqgis

I have layer of points that correspond to a layer of lines. I need to find the distance from the beginning and end point of the line to the corresponding point. I used line_locate_point to get the distance from the start point but I can not figure out how to calculate the distance from the end point. Here's what I have for the start point.

line_locate_point(geometry:=geometry(get_feature('path','Jct_ID',"Point Code")),point:=$geometry)

enter image description here

Best Answer

Calculate Distance of whole line - distance from the start point (pseudocode) - use this expression:

length (geometry(get_feature('path','Jct_ID',"Point Code")))-
line_locate_point(geometry(get_feature('path','Jct_ID',"Point Code")),$geometry)

or, alternatively (where line 3 contains the expression for the line):

with_variable (
    'line',
    geometry(get_feature('path','Jct_ID',"Point Code")),
    length(@line) - line_locate_point(@line,$geometry))
Related Question