Skip to content

Commit

Permalink
Merge pull request #31860 from rouault/fix_30518
Browse files Browse the repository at this point in the history
[OGR provider] Invalid feature count on layer reload (fixes #30518)
  • Loading branch information
rouault committed Sep 18, 2019
2 parents 3ff8ca5 + 2a2cb87 commit 1494246
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -4530,6 +4530,7 @@ void QgsOgrProvider::close()

void QgsOgrProvider::reloadData()
{
mFeaturesCounted = QgsVectorDataProvider::Uncounted;
bool wasValid = mValid;
forceReload();
close();
Expand Down
23 changes: 23 additions & 0 deletions tests/src/python/test_provider_ogr.py
Expand Up @@ -586,6 +586,29 @@ def testBoolFieldEvaluation(self):
self.assertEqual([f[0] for f in vl.getFeatures()], [True, False, NULL])
self.assertEqual([f[0].__class__.__name__ for f in vl.getFeatures()], ['bool', 'bool', 'QVariant'])

def testReloadDataAndFeatureCount(self):

filename = '/vsimem/test.json'
gdal.FileFromMemBuffer(filename, """{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": null, "geometry": { "type": "Point", "coordinates": [2, 49] } },
{ "type": "Feature", "properties": null, "geometry": { "type": "Point", "coordinates": [3, 50] } }
]
}""")
vl = QgsVectorLayer(filename, 'test', 'ogr')
self.assertTrue(vl.isValid())
self.assertEqual(vl.featureCount(), 2)
gdal.FileFromMemBuffer(filename, """{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": null, "geometry": { "type": "Point", "coordinates": [2, 49] } }
]
}""")
vl.reload()
self.assertEqual(vl.featureCount(), 1)
gdal.Unlink(filename)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1494246

Please sign in to comment.