I have a set of points as well as a line layer (a road network) as given below.

Point and line layers

After I snap the points to the line layer the result is as follows.

Points snapped to lines

The result that I need is to clip/trace the line layer segment spanning the point layer like this:

Traced line layer

I've tried many methods on QGIS from using a buffer on the snap points to clip, to using join attributes by nearest/location, however due to the inconsistency of the placement of the points on the line layer I always end up with many gaps, unnecessary segments. I am also unable to use the points to path feature because the points don't have an attribute which indicates order.

What's the best way that I could try to achieve this result? I'm willing to even venture into solutions outside of QGIS (GRASS, GeoPandas) as long as it's open source.

  • You could add the ascending ID manually?
    – Erik
    Commented Aug 30, 2022 at 11:37
  • 1
    Without having your data this is impossible to solve
    – Bera
    Commented Aug 30, 2022 at 12:19

1 Answer 1


You can do that with Network tools. Use Menu Processing > Toolbox > Shortest Path (point to layer) (see documentation) with these settings:

  • as Vector layer representing network, use your line layer.
  • for Start Point, click on the first point (use activated snapping to "catch" the point)
  • for Vector layer with end points, use your points layer - no need to snap them to the line beforehand.

However, you need a proper network: where lines intersect or touch, they must have a common vertex for the tool to find a connection between lines. Alternatively, expand Advanced Parameters and set a (small) topology tolerence.

When you run the tool, you get the desired output - see screenshot below.

Be aware: If you want to clean the result, explode the lines and delete duplicate geometries. If necessary, re-merge the lines and convert from Multipart to single parts to get simple lines as output.

Screenshot: yellow lines created based on black input network and red points:

enter image description here

  • Thanks. I tried this but I seem to end up with many extra segments: imgur.com/V5HZfnY
    – Nandula
    Commented Sep 2, 2022 at 4:06
  • From the Image it does not become clear which lines are Desiree outputs and which not. Can you add details? Can you share Project + data?
    – Babel
    Commented Sep 2, 2022 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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