Bug report #8822
OGR: Repack in running session
|Affected QGIS version:||2.0.1||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||17515|
OGR does not delete features in shapefiles immediately. Instead, it marks and skips features when they are being deleted, until the REPACK command is issued which then really deletes them. This command also assigns new feature ids to the features.
Currently REPACK is called, whenever a spatial index is created on a shapefile. When a feature is being deleted, createSpatialIndex() is called in order to issue REPACK.
This can happen at any time the layer is opened and can lead to undesiered effects. E.g. open an attribute table of a layer, delete features with low feature ids and save the edits. The attribute table will show ERROR instead of the attribute values, because the feature ids have silently changed.
I would propose to ONLY call REPACK, when closing a layer. Attention has to be paid if indexes need to be rebuilt or if OGR does this automatically.
Repack shapefiles when saving after deleting features
- QgsVectorDataProvider::dataChanged() will be emitted
- QgsVectorLayer::dataChanged() will be emitted
- Clears QgsVectorLayerCache
- Reloads the attribute table
- Clears the selection
Looking forward to people complaining about their lost selection...
#1 Updated by Matthias Kuhn almost 8 years ago
I suspect the following report is connected to this bug:
Looking at the OGR sourcecode, .shx files are rewritten as well, so the index should be ok I think.
If there is no objection, I am going to implement this.