1

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

Vince
  • 20,017
  • 15
  • 45
  • 64
brink
  • 820
  • 9
  • 23

1 Answers1

4

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))
Babel
  • 71,072
  • 14
  • 78
  • 208
  • Elegant and simple. It didn't occur to me to just subtract the length. Thank you very much. – brink Aug 31 '21 at 21:47