I'm trying to join the nearest points within a group to create a line layer. I have the points, unique ids per point, and the grouping ids.
This question seems very easy or at least should have been answered before now but I just can't find a solution to it. This question was asked in 2015 but no answer has been provided - How to order points along a line?
I have tried to implement the solutions from here and tried to use
Points to path but my points are not ordered so it doesn't work. When using
Points to Path and using the group id as the
Path group expression I get the attached screenshot where some lines are good, they just connect to the nearest points but then other lines are created that do not join the nearest points to one another. I have double checked the points to make sure they are under the same group id and they are.
I have also tried to implement the solution from here, which uses
geometry by expression using a
Distance matrix but it doesn't join the correct points. I used the code
make_line (geometry ( get_feature_by_id( 'Centroids_aa787be7_c4bb_4ff5_96a9_d0075ff72b9a', "InputID")), geometry (get_feature_by_id('Centroids_aa787be7_c4bb_4ff5_96a9_d0075ff72b9a', "TargetID")))
which results in this:
Ideally I would like to be able to just order my points within each grouping and use
Points to Path all in QGIS but I can't figure out a way to do so. Does anyone have a solution to either order (not just number) points within a group or an alternative solution that allows me to join nearest points within a group? Currently running QGIS version 3.32.3