[GIS] Automatically assigning numbers to point file in various order in QGIS

field-calculatorqgisspatial-sort

I know how to automatically assign numbers to a new point files using the $rownum function in the field calculator. However it does it from the top-left over and down like reading a book.

I could manually add the numbers myself that would be very time consuming in large point features.

What I'm wanting to do, as shown in the picture, is the top-left group of points to have them labeled 1 to 33 and the bottom-right group from 34 to the end.

Also, if I wanted to label the points vertically and start at the furthest top-left point and go down and then to the right, how would that be accomplished.

I'm sure that there is just some "code" I need to put into the field calculator but I do not know how.

enter image description here

Best Answer

$rownum is the row number and has absolutely nothing to do with how the features are arranged on the map.

You could select all points in the left polygon and calculate an id such as 100+$rownum and do the same with the right one but 200+$rownum. That won't result in consecutive ids, but depending on the use case it might be enough.

Related Question