1

I created a grid of hexagons and kept only the hexagons in a circle. In effect many hexagon-ids are missing and the remaining ones start at 1409.

enter image description here

I want them to be numbered consecutively in a logic way starting with 1 (top to bottom, left to right); i. e. 1409 should be 1, 1410 should be 2 ... 1495 should be 9, 1496 should be 10 ...

The attempt to use the expression @row_number in the field calculator as suggested by this post: Filling column with consecutive numbers in QGIS used the Feature ID + 1 for the new value, as can be seen in the column 'test'.

enter image description here

From the list of functions (https://docs.qgis.org/testing/en/docs/user_manual/expressions/functions_list.html#functions-list) I understand that it should take the row-number instead, which would result in the exact sequence I desire.

8
  • Not an answer but there is a sort and number plugin which you could use instead.
    – John
    Commented Dec 30, 2022 at 18:13
  • After deleting the features, did you toggle edit mode to save the changes? If not, no wonder @row_number returns the same value
    – Babel
    Commented Dec 30, 2022 at 19:02
  • @John Thank you very much, I use the "sort and number"-plugin as a workaraound. Still not the neatest solution, but it does the job.
    – SAM
    Commented Dec 30, 2022 at 19:49
  • Babel: I exported the selected hexagons as a seperate shape-file, so saving should not be a problem, I also closed and reopened QGIS many times. Also the row-numbers started with 1, so it is not that the original rows have been used, as the original hexagon 1 has been deleted. Instead I received a consecutive series of numbers 1 to 5966, just as I wanted, only their placing was weird with 1 somewhere in the middle at the bottom. At the original grid, the 1 was in the upper left corner, which I cut off. With a rectangular grid as the original one, the expression @row_number works fine btw.
    – SAM
    Commented Dec 30, 2022 at 20:01
  • 1
    I can't reproduce the behivour you describe, when using @row_number, I get an increasing no. starting with 1, see screenshot: i.sstatic.net/cFFNp.jpg Can you provide/share the exported shapefile?
    – Babel
    Commented Dec 30, 2022 at 21:01

1 Answer 1

1

It turns out to work just fine, if I save every step as a shape-file. Originally I always used the original grid as a temporary scratch layer and saved only the selected hexagons which form a circle. This created the error. So just make sure to save every step as a shape-file, it is worth the effort. Many thanks to Babel https://gis.stackexchange.com/users/88814/babel for forcing me to rethink the process.

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.