5

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

Chris W
  • 15,720
  • 2
  • 29
  • 47
user29003
  • 51
  • 2
  • 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. – Devdatta Tengshe Apr 09 '14 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 09 '14 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? – Devdatta Tengshe Apr 09 '14 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 09 '14 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. – Devdatta Tengshe Apr 09 '14 at 12:16
  • Maybe it will work if I explain my workflow to make the points. Step1 Upload boundary, step2 create buffer, step 3 create polygon grid, step 4 create points of polygon grid, step 5 clip points with buffer boundary. As you can see, the number comes direct from the clipping, so to renumber each point will take a very long time, then I can just as well manually add each point, the the correct sequence. The numbers of the points will always change according to the different boundaries. The numbering isn't important, the route is. Make sense? – user29003 Apr 09 '14 at 12:27
  • It seems to me you have two different problems. The first is when the grid is created the numbering is by and restarts at each row as in your first image. You want a numbering scheme that orders 6 below 5 instead of 1. I don't know the proper terms for those two grid progressions. The second is that you're trying to find the most efficient route between points, which has nothing to do with numbering and therefore cannot be fully solved by a simple sort. In ArcGIS this would be a network analyst routing problem. Applying a solution to your first problem only gets you part of the way there. – Chris W Apr 09 '14 at 19:45
  • @user29003, did you find a solution for this yet? – Simbamangu Sep 01 '14 at 14:55

1 Answers1

3

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

Kazuhito
  • 30,746
  • 5
  • 69
  • 149