[GIS] How to allocate a $rownum in reverse order in QGIS

atlasfield-calculatorqgis

How can I allocate the $rownum value in reverse order in QGIS?

I have a created a grid layer to use in an atlas and the ID allocated is from top left to bottom right – which is what I want if I want to create a $rownum attribute to use as the map number in my atlas (e.g. 1 – 78)

But I have selected only those grid polygons that have relevant data beneath them for my maps, so I have created a grid layer that is a subset of the original. In this subset grid, the ID numbers have been reversed – that is, they go from bottom right to top left so if I create the $rownum field the numbers will be in that reverse [new] order. (e.g. 45 – 1).

So I want to allocate that $rownum attribute in reverse order so that the atlas maps read from top left to bottom right.

Can anyone help?

Best Answer

Internally you cannot modify Row Numbers. Your calculation into a new field is the number of rows - $rownum:

enter image description here

This will reverse the $rownum into a field. $rownum (row number) objects cannot be modified as they are handled by the driver/database. In the case of shapefiles they are transient as edited features move to the end and then get compressed back to 0 based, unique and ascending on save edits.

Related Question