4

I have a to export points along a specific path.

We have a point layer of 40.000 points (representing water customers).

We created a polyline from one point to the next, and so on (representing the way the meter reader has to walk from one customer to the next).

Now, we need to export the customers according to the order the points appear on the created polyline(representing the path the the meter reader needs to walk). We selected the points according to their position on the ployline (in geographic order) The exported file should contain the points in order according to the direction of the path. (It's for the creation of a reading list for water meter readers.) However, the exported file contains the points according to the FID field number instead of the selected order.

We are using QGIS 3.24, having a CSV file containing around 40.000 entries (representing customers). We're linking the CSV file to a point layer containing mainly the one "meter number" [numeric] as primary key to link it to the CSV file (the account number).

1
  • Could you share some sample data/screenshots to illustrate, that will help providing you with an answer
    – Kasper
    Feb 21, 2023 at 16:52

2 Answers 2

7

As long as your route segments were drawn in the desired order, you can use the tool Extract vertices on the line layer. The vertex_index field of the resulting point layer is the order in which they appear along the line (irrespective of the original point $id's).

enter image description here

You can then use Join by nearest on the new Vertices layer and your original points layer to transfer the attributes of the original points.

1
  • it works ! as we have to create arround 200 routes, it will take some time... however, Great Answer! Feb 22, 2023 at 13:57
4

You can achieve this using a virtual layer (though 40,000 points might be pushing it a bit too much). It is assuming there is a single line in the layer.

Go to the menu Layer > Add Layer > Add/Edit Virtual Layer..., enter the following query and adjust for your layer name. Here it is returning all fields from the point layer (pt.*) but you can list individual fields instead (pt.id, pt.house_number, pt.street_name)

select pt.*
from my_point_layer pt, my_line_layer ln
order by ST_Line_Locate_Point(ln.geometry, pt.geometry)

This query will work with points on or near the line. In the following example, points were digitized in a random order:

enter image description here

enter image description here

2
  • 1
    Building on this approach, I have been using this Virtual Layer solution for a few years to order points by multiple lines, based on lineid field of closest line and then by position along that line. OP I think you may find it useful if you are open to using it. Haven't tested it with 40,000 points of course... gis.stackexchange.com/a/328813/98784
    – she_weeds
    Feb 21, 2023 at 21:49
  • works out fine (and elegant) for smaller files. in our case, we have been cutting the large file into smaller parts. Attention to missing or double "fid" ! Feb 22, 2023 at 17:52

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.