From 7d41d3a065ef987a82603f19e721eddb136c4522 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 28 Apr 2020 09:24:39 +0000 Subject: [PATCH] Fix subset string is ignored for vector layers when running GDAL algorithms --- python/plugins/processing/algs/gdal/GdalAlgorithm.py | 3 ++- .../processing/tests/GdalAlgorithmsGeneralTest.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/python/plugins/processing/algs/gdal/GdalAlgorithm.py b/python/plugins/processing/algs/gdal/GdalAlgorithm.py index 4ad9db2bfaa3..650b4c4571ff 100644 --- a/python/plugins/processing/algs/gdal/GdalAlgorithm.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithm.py @@ -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, diff --git a/python/plugins/processing/tests/GdalAlgorithmsGeneralTest.py b/python/plugins/processing/tests/GdalAlgorithmsGeneralTest.py index 38d7978d133a..dccadc5abeed 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsGeneralTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsGeneralTest.py @@ -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')