Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running algs with virtual layers #59465

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions python/plugins/processing/algs/gdal/Buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if source is None:
raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))
fields = source.fields()
source_details = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)

geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
source_details = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing=True)
# QgsVectorFileWriter defaults to geometry column called geom when exporting virtual, memory and grass layer
if source_details.layer_name == 'INPUT' and 'INPUT.gpkg' in source_details.connection_string:
geometry = parameters[self.GEOMETRY] = 'geom'
else:
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
Comment on lines +103 to +108
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of handling this here, I'd rather see:

  1. An optional "geometry_column_name" field added to the GdalConnectionDetails class. (defaulting to None)
  2. GdalAlgorithm.getOgrCompatibleSource updated so that the geometry_column_name field is set to "geom" when the source provider is the virtual provider
  3. All the GDAL algorithms which have a geometry column name updated to ignore this value and use the geometry_column_name from the GdalConnectionDetails object if it's set

How's that sound to you?

distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
fieldName = self.parameterAsString(parameters, self.FIELD, context)
dissolve = self.parameterAsBoolean(parameters, self.DISSOLVE, context)
Expand All @@ -122,6 +125,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = [
output_details.connection_string,
source_details.connection_string,
'-nlt PROMOTE_TO_MULTI',
'-dialect',
'sqlite',
'-sql'
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GdalAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def getOgrCompatibleSource(self,
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
Expand Down
Loading