Original question: I would like to sort my points in QGIS. See image

Restated question: The grid tool currently numbers by starting at R1C1 and going to R1Cx, then R2C1 to R2Cx. How do I number the points from R1C1 to R1Cx, then R2Cx to R2C1? Can the solution be applied after a regular grid has been destroyed (points removed) or does it need to be applied to a whole grid, assuming no option for this ordering scheme exists in the grid creation tool itself?

The point is to avoid the long 'row reset' or 'back to start of row' line as this wastes time and fuel, rather than moving directly down to the next row.

enter image description here

enter image description here

  • 2
    what is the Logic behind this route? How do you know that the path should start at 5, and not at 1? Once you figure out that logic, we can then look into implementing it. Apr 9, 2014 at 10:28
  • I want to use the route to create a flight path to take aerial images. The path can start and 1, it does not matter, or the path can start and the NW corner and end at the SE corner. Which ever way so long as it makes that snake like path instead of the one on the left.
    – user29003
    Apr 9, 2014 at 11:02
  • 1
    When we are dealing with computers, we need to tell them exactly what to do. your current requirement is rather vague. snake like path can mean different things in different contexts. Do you always have an exact rectangular array of points? You need to give more details, and need to be more specific than this. What attributes do your points have? Do you want to do this only on the basis of geometry? what have you tried so far? where are you stuck? Apr 9, 2014 at 11:27
  • Apologies for not expressing my self well enough. See attached image in original post. To answer your first question, no the points wont always be rectangular. The attributes of the points are of no use to me, so yes, the sort will be only on geometry basis.
    – user29003
    Apr 9, 2014 at 12:07
  • Sorry If I came off rude; That wasn't my intention. I'm trying to say that your requirement is vague. Even with the latest image, I can think of several lines that could be drawn. It might be easiest to solve, if you could manually number the points. Code could then be written which creates a line based on the numbering that you have provided. Apr 9, 2014 at 12:16

1 Answer 1


If it is ok to draw an imaginary flight-path as a guide, this can be done easily now (QGIS >= 2.18).

(1) Draw a line layer (Guide_line). Note this guide line does not have to follow exact point locations. Give it a unique id field (id) for the line. In this example I have a line id = 1.

enter image description here

(The id number of the points on the picture is chosen at random.)

(2) Open the attribute table of points layer, and add a new decimal field by:

line_locate_point(geometry:=geometry(get_feature('Guide_line', 'id', '1')), point:=$geometry)

(3) The above expression returns distance along the line. Use this field to sort the table (for instance using MMQGIS | Sort tool) and add a new field by $rownum or @row_number).

enter image description here

(extra note): Any kind of flight route will do.

enter image description here

  • Very interesting solution!
    – Simbamangu
    Jun 6, 2018 at 18:42

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.