Skip to content
Permalink
Browse files

Fix subset string is ignored for vector layers when running GDAL algo…

…rithms
  • Loading branch information
github-actions authored and nyalldawson committed Apr 29, 2020
1 parent 8146e75 commit 7d41d3a065ef987a82603f19e721eddb136c4522
@@ -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 7d41d3a

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