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 26, 2021
1 parent b40182f commit e65a22a5febfd6501f281a014adb363e0b65d7bf
Showing with 26 additions and 2 deletions.
  1. +0 −2 src/core/providers/ogr/qgsogrprovider.cpp
  2. +26 −0 tests/src/python/test_provider_shapefile.py
@@ -5195,7 +5195,6 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
ds->hDS, layerIndex );
if ( hLayer )
{
OGR_L_SetAttributeFilter( hLayer, nullptr );
layerName = QString::fromUtf8( OGR_L_GetName( hLayer ) );
}
}
@@ -5252,7 +5251,6 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
ds->hDS, layerIndex );
if ( hLayer )
{
OGR_L_SetAttributeFilter( hLayer, nullptr );
layerName = QString::fromUtf8( OGR_L_GetName( hLayer ) );
}
}
@@ -22,12 +22,14 @@
from osgeo import gdal
from qgis.core import (
QgsApplication,
QgsDataProvider,
QgsSettings,
QgsFeature,
QgsField,
QgsGeometry,
QgsVectorLayer,
QgsFeatureRequest,
QgsRectangle,
QgsVectorDataProvider,
QgsWkbTypes,
QgsVectorLayerExporter,
@@ -1079,6 +1081,30 @@ def testEncoding(self):
self.assertTrue(vl.isValid())
self.assertEqual([f.attributes() for f in vl.dataProvider().getFeatures()], [['abcŐ'], ['abcŐabcŐabcŐ']])

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 e65a22a

Please sign in to comment.