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.

9
  • Not an answer but there is a sort and number plugin which you could use instead.
    – John
    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
    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
    Dec 30, 2022 at 19:49
  • 1
    I can't reproduce the behivour you describe, when using @row_number, I get an increasing no. starting with 1, see screenshot: i.stack.imgur.com/cFFNp.jpg Can you provide/share the exported shapefile?
    – Babel
    Dec 30, 2022 at 21:01
  • 2
    @Babel I will do this, but as it is my own answer I have to wait 2 days to be able to do so.
    – SAM
    Jan 1 at 0:15

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 that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.