Skip to content
Permalink
Browse files
[OGR provider] Fix conflict between layers using same OGR datasource …
…and layer with subset strings (fixes #43361)
  • Loading branch information
rouault authored and nyalldawson committed May 25, 2021
1 parent 6d7e411 commit cf49d2517c0c02c0b9022804dbe750aa09724b57
Showing with 25 additions and 2 deletions.
  1. +0 −2 src/core/providers/ogr/qgsogrprovider.cpp
  2. +25 −0 tests/src/python/test_provider_shapefile.py
@@ -5633,7 +5633,6 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
ds->hDS, layerIndex );
if ( hLayer )
{
OGR_L_SetAttributeFilter( hLayer, nullptr );
layerName = QString::fromUtf8( OGR_L_GetName( hLayer ) );
}
}
@@ -5690,7 +5689,6 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
ds->hDS, layerIndex );
if ( hLayer )
{
OGR_L_SetAttributeFilter( hLayer, nullptr );
layerName = QString::fromUtf8( OGR_L_GetName( hLayer ) );
}
}
@@ -30,6 +30,7 @@
QgsVectorLayer,
QgsFeatureRequest,
QgsProviderRegistry,
QgsRectangle,
QgsVectorDataProvider,
QgsWkbTypes,
QgsVectorLayerExporter,
@@ -1086,6 +1087,30 @@ def testSkipFeatureCountOnSubLayers(self):
self.assertTrue(len(sublayers) > 1)
self.assertEqual(sublayers[0].split(QgsDataProvider.sublayerSeparator())[2], '-1')

def testLayersOnSameOGRLayerWithAndWithoutFilter(self):
"""Test fix for https://github.com/qgis/QGIS/issues/43361"""
file_path = os.path.join(TEST_DATA_DIR, 'provider', 'shapefile.shp')
uri = '{}|layerId=0|subset="name" = \'Apple\''.format(file_path)
options = QgsDataProvider.ProviderOptions()
vl1 = QgsVectorLayer(uri, 'vl1', 'ogr')
vl2 = QgsVectorLayer(uri, 'vl2', 'ogr')
vl3 = QgsVectorLayer('{}|layerId=0'.format(file_path), 'vl3', 'ogr')
self.assertEqual(vl1.featureCount(), 1)
vl1_extent = QgsGeometry.fromRect(vl1.extent())
self.assertEqual(vl2.featureCount(), 1)
vl2_extent = QgsGeometry.fromRect(vl2.extent())
self.assertEqual(vl3.featureCount(), 5)
vl3_extent = QgsGeometry.fromRect(vl3.extent())

reference = QgsGeometry.fromRect(QgsRectangle(-68.2, 70.8, -68.2, 70.8))
assert QgsGeometry.compare(vl1_extent.asPolygon()[0], reference.asPolygon()[0],
0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl1_extent.asWkt())
assert QgsGeometry.compare(vl2_extent.asPolygon()[0], reference.asPolygon()[0],
0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl2_extent.asWkt())
reference = QgsGeometry.fromRect(QgsRectangle(-71.123, 66.33, -65.32, 78.3))
assert QgsGeometry.compare(vl3_extent.asPolygon()[0], reference.asPolygon()[0],
0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl3_extent.asWkt())


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

0 comments on commit cf49d25

Please sign in to comment.