Skip to content
Permalink
Browse files

[processing] Fix subset string is ignored for vector layers when

running GDAL algorithms

If a subset string is set, we must export the subset of the layer
for use by the GDAL command*

Fixes #35981

* well, we probably **should** just build the gdal command to include
the SQL definition of the subset filter, but that's non-trivial, so
this fix is a good simple solution for now
  • Loading branch information
nyalldawson committed Apr 28, 2020
1 parent a870664 commit 40db7f9efdcc3c168bc5b954809d96089a2756ed
@@ -99,7 +99,8 @@ def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback,
ogr_data_path = 'path_to_data_file'
ogr_layer_name = 'layer_name'
elif input_layer.dataProvider().name() == 'ogr':
if executing and isinstance(parameters[parameter_name], QgsProcessingFeatureSourceDefinition) and parameters[parameter_name].selectedFeaturesOnly:
if executing and (isinstance(parameters[parameter_name], QgsProcessingFeatureSourceDefinition) and parameters[parameter_name].selectedFeaturesOnly) \
or input_layer.subsetString():
# parameter is a vector layer, with OGR data provider
# so extract selection if required
ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
@@ -164,6 +164,18 @@ def testGetOgrCompatibleSourceFromOgrLayer(self):
path, layer = alg.getOgrCompatibleSource('INPUT', parameters, context, feedback, False)
self.assertEqual(path, source)

# with subset string
vl.setSubsetString('x')
path, layer = alg.getOgrCompatibleSource('INPUT', parameters, context, feedback, False)
self.assertEqual(path, source)
# subset of layer must be exported
path, layer = alg.getOgrCompatibleSource('INPUT', parameters, context, feedback, True)
self.assertNotEqual(path, source)
self.assertTrue(path)
self.assertTrue(path.endswith('.gpkg'))
self.assertTrue(os.path.exists(path))
self.assertTrue(layer)

# geopackage with layer
source = os.path.join(testDataPath, 'custom', 'circular_strings.gpkg')
vl2 = QgsVectorLayer(source + '|layername=circular_strings')

0 comments on commit 40db7f9

Please sign in to comment.
You can’t perform that action at this time.