mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
[processing][gdal] Ignore 'selected features only' setting when
creating command preview Since this has no meaning outside of a QGIS session Refs #19451
This commit is contained in:
parent
ed94b693e9
commit
27d447b79d
@ -32,6 +32,7 @@ from qgis.PyQt.QtCore import QUrl, QCoreApplication
|
||||
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsVectorFileWriter,
|
||||
QgsProcessingFeatureSourceDefinition,
|
||||
QgsProcessingAlgorithm,
|
||||
QgsProcessingContext,
|
||||
QgsProcessingFeedback)
|
||||
@ -75,6 +76,12 @@ class GdalAlgorithm(QgsProcessingAlgorithm):
|
||||
Interprets a parameter as an OGR compatible source and layer name
|
||||
:param executing:
|
||||
"""
|
||||
if not executing and parameter_name in parameters and isinstance(parameters[parameter_name], QgsProcessingFeatureSourceDefinition):
|
||||
# if not executing, then we throw away all 'selected features only' settings
|
||||
# since these have no meaning for command line gdal use, and we don't want to force
|
||||
# an export of selected features only to a temporary file just to show the command!
|
||||
parameters = {parameter_name: parameters[parameter_name].source}
|
||||
|
||||
input_layer = self.parameterAsVectorLayer(parameters, parameter_name, context)
|
||||
ogr_data_path = None
|
||||
ogr_layer_name = None
|
||||
|
||||
@ -153,6 +153,16 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
self.assertTrue(res.isValid())
|
||||
self.assertEqual(res.featureCount(), 2)
|
||||
|
||||
# with memory layers - if not executing layer source should be ignored and replaced
|
||||
# with a dummy path, because:
|
||||
# - it has no meaning for the gdal command outside of QGIS, memory layers don't exist!
|
||||
# - we don't want to force an export of the whole memory layer to a temp file just to show the command preview
|
||||
# this might be very slow!
|
||||
ogr_data_path, ogr_layer_name = alg.getOgrCompatibleSource('INPUT', parameters, context, feedback,
|
||||
executing=False)
|
||||
self.assertEqual(ogr_data_path, 'path_to_data_file')
|
||||
self.assertEqual(ogr_layer_name, 'layer_name')
|
||||
|
||||
QgsProject.instance().removeMapLayer(layer)
|
||||
|
||||
def testGetOgrCompatibleSourceFromOgrLayer(self):
|
||||
@ -173,6 +183,12 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
path, layer = alg.getOgrCompatibleSource('INPUT', {'INPUT': vl.id()}, context, feedback, False)
|
||||
self.assertEqual(path, source)
|
||||
|
||||
# with selected features only - if not executing, the 'selected features only' setting
|
||||
# should be ignored (because it has no meaning for the gdal command outside of QGIS!)
|
||||
parameters = {'INPUT': QgsProcessingFeatureSourceDefinition(vl.id(), True)}
|
||||
path, layer = alg.getOgrCompatibleSource('INPUT', parameters, context, feedback, False)
|
||||
self.assertEqual(path, source)
|
||||
|
||||
def testGetOgrCompatibleSourceFromFeatureSource(self):
|
||||
# create a memory layer and add to project and context
|
||||
layer = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user