Bug report #8822

OGR: Repack in running session

Added by Matthias Kuhn about 6 years ago. Updated about 5 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Data Provider/OGR
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

Description

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.


Related issues

Related to QGIS Application - Bug report #8317: Deleted features are not really deleted. Closed 2013-07-17
Related to QGIS Application - Bug report #11007: Deleted/edited features within SHAPEFILE are still recogn... Closed 2014-08-05
Related to QGIS Application - Bug report #7540: Merge tool bug when a shapefile is loaded multiple times Closed 2013-04-07
Related to QGIS Application - Bug report #11398: Buggy/unreadable polygons created by functions splitting/... Closed 2014-10-13
Related to QGIS Application - Bug report #11296: Deleting shapes in shapefiles does not work Closed 2014-09-30
Related to QGIS Application - Bug report #11989: Unexpected behaviour in QGIS Node Tool when adding vertex Closed 2015-01-14

Associated revisions

Revision ba76c990
Added by Matthias Kuhn almost 6 years ago

[ogr] Only call repack when closing a data provider
Fix #8822

Revision b9959731
Added by Matthias Kuhn almost 6 years ago

[ogr] Only call repack when closing a data provider
Fix #8822

Revision cf7e016b
Added by Jürgen Fischer over 5 years ago

ogr: don't create spatial index for shapes after deletes. That was supposed to
also run a repack and doesn't work without (fixes #10483, refs #8317, refs #8822)

Revision 7d7cdcd3
Added by Matthias Kuhn over 4 years ago

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

Fix #10560
Fix #11989
Refs #8317
Refs #8822
Refs #10483
Refs #11007
Refs #7540
Refs #11398
Refs #11296

History

#1 Updated by Matthias Kuhn almost 6 years ago

I suspect the following report is connected to this bug:

http://gis.stackexchange.com/questions/58101/how-to-avoid-creating-corrupt-shapefiles-during-editing

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.

#2 Updated by Matthias Kuhn almost 6 years ago

  • Status changed from Open to Closed

#3 Updated by Giovanni Manghi about 5 years ago

Hi Matthias,

would you mind have a look at

#11007

I don't know if the issue described there is related to ogr repack, but anyway seems pretty severe (even if not strictly a regression) as is causes a major interoperability issue.

Thanks in advance.

Also available in: Atom PDF