1

I have a line layer with some lines, and a point layer whose points are located on those lines.

Now I need to get the position "along" the line where each point is (as in distance from start of the line along the line)

  • A point located at the start of the line would be at 0 meters from start
  • A point at the end of the line would be at <length> meters from start
  • A point anywhere in between would be calculated accordingly

I found two answers that can surely help me achieve this, but they're using Python, and I'm almost sure there is a very simple button or processing tool that would do this instead.

GforGIS
  • 3,126
  • 3
  • 19
  • 38

1 Answers1

2

You can use the field calculator on the POINT_Layer. I don't think there is a one-click tool.

line_locate_point(aggregate('YOUR_LINE_LAYER_NAME','collect',$geometry),$geometry)

enter image description here

enter image description here

EDIT - Based on comment by she_weeds

The difference between the two methodes aggregate/collect and overlay_nearest can be seen if you have two lines in the line layer.

aggregate/collect count the distance along both lines and overlay_nearest starts with 0 at the beginning of each line.

line_locate_point(overlay_nearest('YOUR_LINE_LAYER_NAME',$geometry)[0], $geometry)

enter image description here

enter image description here

Xeppit
  • 1,315
  • 5
  • 12
  • 2
    An alternative to this is using line_locate_point(overlay_nearest('YOUR_LINE_LAYER_NAME',$geometry)[0], $geometry) so that each point has its distance measured along the closest line, rather than a collection of all the line layers' features – she_weeds Jan 22 '24 at 21:31
  • @she_weeds tried to improve answer on your comment – Xeppit Jan 22 '24 at 22:18
  • Any way to return this in meters? (my current projection is in degrees) – Daniel Möller Jan 23 '24 at 13:36
  • 1
    @DanielMöller you would be much better off using a projected CRS to begin with, but if you must work in degrees, you could adapt the expression by wrapping any instance of $geometry with transform() to convert from a degree-based CRS to an appropriate meter-based CRS. – she_weeds Jan 24 '24 at 22:45