1

I have a shapefile which does not have any ID column. I put them in a validator, which indicates the ID of faulty features, based on the DBF line order. But by opening the shapefile attribute table in QGIS (tried 3.4 and 3.22), I cannot know the ID of each feature, since QGIS apply a "default" sort which does not match the original file order (it seems to be due to an old bug).

The only way I found is to hover each feature one by one, and check the feature ID in the tooltip ... it can be VERY, VERY long.

An example can be seen in this related answer of another question: Example

Is there any other way to do see DBF line number in QGIS? And to sort attribute table using it? Is the bug causing this still active?

5
  • Have you tried adding another ID column using @rownumber?
    – Erik
    Aug 8, 2022 at 10:19
  • 2
    Or using $id?
    – Babel
    Aug 8, 2022 at 10:26
  • 1
    secondary question: delete this here and post it as a separate question.
    – Babel
    Aug 8, 2022 at 10:27
  • since the ticket is not marked as resolved I would assume it is there - if it's really bothering you then you'll need to get it fixed either by writing some code or paying someone to do it.
    – Ian Turton
    Aug 8, 2022 at 12:28
  • 2
    Be careful! -- Record ID is the only thing that ties the .shp/.shx pair to .dbf. If you sort the dBase without the geometries, you might never get them to link back up again.
    – Vince
    Aug 8, 2022 at 19:56

1 Answer 1

3

To only sort the attribute table, open it and do right click somewhere on the fieldnames:

enter image description here

Choose sort and enter the expression $id:

enter image description here


To create a new layer, with features ordered by the (previous) feature id, you can run "Order by Expression" from processing toolbox and use the expression $id:

enter image description here

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.