4

At QGIS 3.8.2, I need to populate a field (let's call it field_a) in a sequentially increasing (1, 2, 3,...) order. However, I need the sequence to increase in the order that the table is currently sorted (let's say that it is currently sorted by field_b).

I tried @row_number, but the increasing sequence does not follow the current sort order. I think it follows an internal id, but I'm not sure...

  • test in the field calculator $id function, you can find it in therecord and attributes section of the field calculator – Gerardo Jimenez Sep 6 '19 at 19:24
  • @GerardoJimenez Thanks, but $id simply returns the value of the FID. – Stu Smith Sep 6 '19 at 20:54
5

Try the Sort and Number QGIS plugin, available in the Plugin Repository.

enter image description here

Information:

Sort and Number plugin

Description

This plugin was coded in response to the recurrent issue of numbering a sorted attribute table, which has (currently) no simple workaround in QGIS. It creates a new field that contains the order of features, after sorting by up to 3 criteria.

UI

First, select the vector layer you want to number. Then, select the fields you want to order. First field has priority on second field, which has priority on third field. Default order is ascending. Check the box next to a field to choose a descending order. Finally, enter the name of the numbering field to create. Default is 'order'.

Changelog

v0.2: - added "sort only selected features" option (thanks to m4x300) - added i18n support (French translation)

v1.0: - compatibilty with QGIS 3.x (not compatible anymore with QGIS 2.x)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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