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...

TomazicM
  • 25,601
  • 22
  • 29
  • 39
Stu Smith
  • 8,252
  • 8
  • 35
  • 84

1 Answers1

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)

Saijin_Naib
  • 2,729
  • 12
  • 25