I have a bunch of points which I have extracted from line features. Now I want to connect them back to a line, but unfortunately, they are not sorted in the correct way, so I always end up with a wild mess.

So I thought about an approach where the line creation starts at a defined start point and then connects the points one by one, always chosing the next vertex based on the minimum distance from the previous one. But I have no idea how to do that in QGIS. Aside from the distance to the next point, I have nothing else to determine the line direction.

Any suggestions welcome (incl. Python coding).

enter image description here


2 Answers 2


You can use ProcessX-Plug-In. It has an algorithm "Nearest Points To Path", you will find in your processing toolbox --> processx --> vector - creation:

enter image description here

In your case you may want to use $x as OrderBy Expression, to make sure the line starts at most-western point.

Example result:

enter image description here

Disclaimer: I am the developer of this Plug-In

  • Using the x-Coordinate is not option. The points resemble a natural river and the "closest" point is not always the next one in x-direction. As shown in the screenshot in the question, the river can move mostly west, but make a short curves towards east as well before continuing west.
    – s6hebern
    Aug 22, 2022 at 12:26
  • 4
    In this case, add a new field to your layer, give the startpoint of the river the value 1 and all other points the value 2. Then use this new field as OrderBy-Expression. But maybe we also misunderstood each other? Just give it a try and report back.
    – MrXsquared
    Aug 22, 2022 at 12:35

If the first answer does not work, you can try the MST plug-in. In the plug-in you can select a point layer. It will connect the points along the shortest path

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.