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

  • That's just line length minus distance to start point.
    – geozelot
    Aug 31, 2021 at 19:23

1 Answer 1


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 (
    geometry(get_feature('path','Jct_ID',"Point Code")),
    length(@line) - line_locate_point(@line,$geometry))
  • Elegant and simple. It didn't occur to me to just subtract the length. Thank you very much.
    – brink
    Aug 31, 2021 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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