diff --git a/python/plugins/processing/algs/gdal/Buffer.py b/python/plugins/processing/algs/gdal/Buffer.py index 63a97eec98fd..dcffbe18aca4 100644 --- a/python/plugins/processing/algs/gdal/Buffer.py +++ b/python/plugins/processing/algs/gdal/Buffer.py @@ -134,8 +134,13 @@ 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) @@ -149,6 +154,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): other_fields = ",*" if other_fields_exist else "" + arguments = [ output_details.connection_string, source_details.connection_string, @@ -167,6 +173,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..2b244407e4e9 100644 --- a/python/plugins/processing/algs/gdal/ClipVectorByExtent.py +++ b/python/plugins/processing/algs/gdal/ClipVectorByExtent.py @@ -84,6 +84,8 @@ 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..3084e4a71303 100644 --- a/python/plugins/processing/algs/gdal/ClipVectorByMask.py +++ b/python/plugins/processing/algs/gdal/ClipVectorByMask.py @@ -94,6 +94,8 @@ 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..6688816b8d45 100644 --- a/python/plugins/processing/algs/gdal/Dissolve.py +++ b/python/plugins/processing/algs/gdal/Dissolve.py @@ -146,9 +146,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) - 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..b2797e11cb42 100644 --- a/python/plugins/processing/algs/gdal/ExecuteSql.py +++ b/python/plugins/processing/algs/gdal/ExecuteSql.py @@ -100,6 +100,8 @@ 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..f86f19cbba42 100644 --- a/python/plugins/processing/algs/gdal/GdalAlgorithm.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithm.py @@ -92,7 +92,7 @@ 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 +108,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/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..3cc9f59b84df 100644 --- a/python/plugins/processing/algs/gdal/OneSideBuffer.py +++ b/python/plugins/processing/algs/gdal/OneSideBuffer.py @@ -151,7 +151,12 @@ 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..c80cb8f8306a 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogr.py +++ b/python/plugins/processing/algs/gdal/ogr2ogr.py @@ -99,6 +99,8 @@ 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..65ff4d80ecae 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py @@ -364,6 +364,8 @@ 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 +375,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