4

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

s6hebern
  • 1,236
  • 10
  • 19
  • See here https://gis.stackexchange.com/questions/382057/create-road-network-from-points/382246#382246 – Babel Aug 22 '22 at 11:56
  • or here https://gis.stackexchange.com/questions/386082/connecting-points-to-lines-in-order-using-qgis?rq=1 – JGH Aug 22 '22 at 11:57
  • Or here https://gis.stackexchange.com/a/419209/88814 – Babel Aug 22 '22 at 11:59
  • Are you sure you do not have any attribute (including id) you could use for ordering? Do you still have original lines available which intersect all these points? – Miro Aug 22 '22 at 12:53

2 Answers2

5

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

MrXsquared
  • 34,292
  • 21
  • 67
  • 117
  • 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 '22 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 '22 at 12:35
1

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