diff --git a/python/plugins/processing/algs/gdal/Buffer.py b/python/plugins/processing/algs/gdal/Buffer.py index 63a97eec98fd..3a30c099f632 100644 --- a/python/plugins/processing/algs/gdal/Buffer.py +++ b/python/plugins/processing/algs/gdal/Buffer.py @@ -134,8 +134,15 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): source_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) + if not source_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) - geometry = self.parameterAsString(parameters, self.GEOMETRY, context) + if source_details.geometry_column_name: + geometry = source_details.geometry_column_name + else: + geometry = self.parameterAsString(parameters, self.GEOMETRY, context) distance = self.parameterAsDouble(parameters, self.DISTANCE, context) fieldName = self.parameterAsString(parameters, self.FIELD, context) dissolve = self.parameterAsBoolean(parameters, self.DISSOLVE, context) @@ -167,6 +174,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): arguments.append(sql) + if source_details.geometry_column_name: + arguments.append("-nlt PROMOTE_TO_MULTI") + if self.parameterAsBoolean(parameters, self.EXPLODE_COLLECTIONS, context): arguments.append("-explodecollections") diff --git a/python/plugins/processing/algs/gdal/ClipVectorByExtent.py b/python/plugins/processing/algs/gdal/ClipVectorByExtent.py index 5676a92ae0c0..31ddba2fe6c6 100644 --- a/python/plugins/processing/algs/gdal/ClipVectorByExtent.py +++ b/python/plugins/processing/algs/gdal/ClipVectorByExtent.py @@ -84,6 +84,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) source = self.parameterAsSource(parameters, self.INPUT, context) if source is None: raise QgsProcessingException( diff --git a/python/plugins/processing/algs/gdal/ClipVectorByMask.py b/python/plugins/processing/algs/gdal/ClipVectorByMask.py index cdf4793c8cc0..c3d6e6fae295 100644 --- a/python/plugins/processing/algs/gdal/ClipVectorByMask.py +++ b/python/plugins/processing/algs/gdal/ClipVectorByMask.py @@ -25,6 +25,7 @@ QgsProcessingParameterDefinition, QgsProcessingParameterString, QgsProcessingParameterFeatureSource, + QgsProcessingException, QgsProcessingParameterVectorDestination, ) from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm @@ -94,6 +95,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) mask_details = self.getOgrCompatibleSource( self.MASK, parameters, context, feedback, executing ) diff --git a/python/plugins/processing/algs/gdal/Dissolve.py b/python/plugins/processing/algs/gdal/Dissolve.py index 133dca5e585c..5f827c9e27ba 100644 --- a/python/plugins/processing/algs/gdal/Dissolve.py +++ b/python/plugins/processing/algs/gdal/Dissolve.py @@ -146,9 +146,16 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) - geometry = self.parameterAsString(parameters, self.GEOMETRY, context) - fieldName = self.parameterAsString(parameters, self.FIELD, context) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) + if input_details.geometry_column_name: + geometry = input_details.geometry_column_name + else: + geometry = self.parameterAsString(parameters, self.GEOMETRY, context) + fieldName = self.parameterAsString(parameters, self.FIELD, context) options = self.parameterAsString(parameters, self.OPTIONS, context) outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) self.setOutputValue(self.OUTPUT, outFile) diff --git a/python/plugins/processing/algs/gdal/ExecuteSql.py b/python/plugins/processing/algs/gdal/ExecuteSql.py index e866395a1620..fda61c1b745a 100644 --- a/python/plugins/processing/algs/gdal/ExecuteSql.py +++ b/python/plugins/processing/algs/gdal/ExecuteSql.py @@ -100,6 +100,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) sql = self.parameterAsString(parameters, self.SQL, context) options = self.parameterAsString(parameters, self.OPTIONS, context) outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) diff --git a/python/plugins/processing/algs/gdal/GdalAlgorithm.py b/python/plugins/processing/algs/gdal/GdalAlgorithm.py index 6ce5279ba254..dcc7d2513ac3 100644 --- a/python/plugins/processing/algs/gdal/GdalAlgorithm.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithm.py @@ -92,7 +92,11 @@ def getOgrCompatibleSource( parameters = {parameter_name: parameters[parameter_name].source} input_layer = self.parameterAsVectorLayer(parameters, parameter_name, context) - if input_layer is None or input_layer.providerType() in ("memory", "grass"): + if input_layer is None or input_layer.providerType() in ( + "virtual", + "memory", + "grass", + ): if executing: # parameter is not a vector layer - try to convert to a source compatible with OGR # and extract selection if required @@ -108,6 +112,7 @@ def getOgrCompatibleSource( return GdalConnectionDetails( connection_string=ogr_data_path, layer_name=GdalUtils.ogrLayerName(ogr_data_path), + geometry_column_name="geom", ) else: # not executing - don't waste time converting incompatible sources, just return dummy strings diff --git a/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py b/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py index 618af021698f..49a8a7b1c087 100644 --- a/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py @@ -159,7 +159,7 @@ def parametersHaveChanged(self): try: commands = self.algorithm().getConsoleCommands( - parameters, context, feedback, executing=False + parameters, context, feedback, executing=True ) commands = [c for c in commands if c not in ["cmd.exe", "/C "]] self.text.setPlainText(" ".join(commands)) diff --git a/python/plugins/processing/algs/gdal/GdalUtils.py b/python/plugins/processing/algs/gdal/GdalUtils.py index dde752aef547..92209e28ff32 100644 --- a/python/plugins/processing/algs/gdal/GdalUtils.py +++ b/python/plugins/processing/algs/gdal/GdalUtils.py @@ -62,6 +62,7 @@ class GdalConnectionDetails: open_options: Optional[list[str]] = None layer_name: Optional[str] = None credential_options: Optional[dict] = None + geometry_column_name: Optional[str] = None def open_options_as_arguments(self) -> list[str]: """ diff --git a/python/plugins/processing/algs/gdal/OgrToPostGis.py b/python/plugins/processing/algs/gdal/OgrToPostGis.py index 5bfcd6b63bb0..64a94a1f4e50 100644 --- a/python/plugins/processing/algs/gdal/OgrToPostGis.py +++ b/python/plugins/processing/algs/gdal/OgrToPostGis.py @@ -397,7 +397,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): pk = self.parameterAsString(parameters, self.PK, context) pkstring = "-lco FID=" + pk primary_key = self.parameterAsString(parameters, self.PRIMARY_KEY, context) - geocolumn = self.parameterAsString(parameters, self.GEOCOLUMN, context) + if input_details.geometry_column_name: + geocolumn = input_details.geometry_column_name + else: + geocolumn = self.parameterAsString(parameters, self.GEOCOLUMN, context) geocolumnstring = "-lco GEOMETRY_NAME=" + geocolumn dim = self.DIMLIST[self.parameterAsEnum(parameters, self.DIM, context)] dimstring = "-lco DIM=" + dim diff --git a/python/plugins/processing/algs/gdal/OneSideBuffer.py b/python/plugins/processing/algs/gdal/OneSideBuffer.py index f9b85b56dec1..fe03833fe248 100644 --- a/python/plugins/processing/algs/gdal/OneSideBuffer.py +++ b/python/plugins/processing/algs/gdal/OneSideBuffer.py @@ -151,7 +151,14 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) - geometry = self.parameterAsString(parameters, self.GEOMETRY, context) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) + if input_details.geometry_column_name: + geometry = input_details.geometry_column_name + else: + geometry = self.parameterAsString(parameters, self.GEOMETRY, context) distance = self.parameterAsDouble(parameters, self.DISTANCE, context) side = self.parameterAsEnum(parameters, self.BUFFER_SIDE, context) fieldName = self.parameterAsString(parameters, self.FIELD, context) diff --git a/python/plugins/processing/algs/gdal/PointsAlongLines.py b/python/plugins/processing/algs/gdal/PointsAlongLines.py index 7b68237a027a..db39a7b18f19 100644 --- a/python/plugins/processing/algs/gdal/PointsAlongLines.py +++ b/python/plugins/processing/algs/gdal/PointsAlongLines.py @@ -114,8 +114,15 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) distance = self.parameterAsDouble(parameters, self.DISTANCE, context) - geometry = self.parameterAsString(parameters, self.GEOMETRY, context) + if input_details.geometry_column_name: + geometry = input_details.geometry_column_name + else: + geometry = self.parameterAsString(parameters, self.GEOMETRY, context) outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) self.setOutputValue(self.OUTPUT, outFile) options = self.parameterAsString(parameters, self.OPTIONS, context) diff --git a/python/plugins/processing/algs/gdal/ogr2ogr.py b/python/plugins/processing/algs/gdal/ogr2ogr.py index 3040b8242eac..ed64588f05d1 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogr.py +++ b/python/plugins/processing/algs/gdal/ogr2ogr.py @@ -99,6 +99,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) convertAllLayers = self.parameterAsBoolean( parameters, self.CONVERT_ALL_LAYERS, context ) diff --git a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py index 364d684067a6..4b2422ca6a1c 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py @@ -364,6 +364,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): input_details = self.getOgrCompatibleSource( self.INPUT, parameters, context, feedback, executing ) + if not input_details.layer_name: + raise QgsProcessingException( + self.invalidSourceError(parameters, self.INPUT) + ) shapeEncoding = self.parameterAsString(parameters, self.SHAPE_ENCODING, context) ssrs = self.parameterAsCrs(parameters, self.S_SRS, context) tsrs = self.parameterAsCrs(parameters, self.T_SRS, context) @@ -373,7 +377,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): pk = self.parameterAsString(parameters, self.PK, context) pkstring = "-lco FID=" + pk primary_key = self.parameterAsString(parameters, self.PRIMARY_KEY, context) - geocolumn = self.parameterAsString(parameters, self.GEOCOLUMN, context) + if input_details.geometry_column_name: + geocolumn = input_details.geometry_column_name + else: + geocolumn = self.parameterAsString(parameters, self.GEOCOLUMN, context) geocolumnstring = "-lco GEOMETRY_NAME=" + geocolumn dim = self.DIMLIST[self.parameterAsEnum(parameters, self.DIM, context)] dimstring = "-lco DIM=" + dim