Skip to content
Permalink
Browse files

[processing][GRASS] Give some more feedback when trying to use

v.external for reading inputs, and if we can't, advise why not
  • Loading branch information
nyalldawson committed Oct 31, 2018
1 parent 676238b commit 82ac04d6f77c6ac4c0699cc6e7302625bc704a39
Showing with 11 additions and 7 deletions.
  1. +11 −7 python/plugins/processing/algs/grass7/Grass7Algorithm.py
@@ -459,7 +459,7 @@ def processInputs(self, parameters, context, feedback):
paramName, parameters, context)
else:
self.loadVectorLayerFromParameter(
paramName, parameters, context, feedback, None)
paramName, parameters, context, external=None, feedback=feedback)
# For multiple inputs, process each layer
elif isinstance(param, QgsProcessingParameterMultipleLayers):
layers = self.parameterAsLayerList(parameters, paramName, context)
@@ -470,7 +470,7 @@ def processInputs(self, parameters, context, feedback):
self.loadRasterLayer(layerName, layer)
# Add a vector layer
elif layer.type() == QgsMapLayer.VectorLayer:
self.loadVectorLayer(layerName, layer, None)
self.loadVectorLayer(layerName, layer, external=None, feedback=feedback)

self.postInputs()

@@ -808,18 +808,19 @@ def loadVectorLayerFromParameter(self, name, parameters, context, feedback, exte
QgsVectorFileWriter.supportedFormatExtensions(),
feedback=feedback)
ogr_layer = QgsVectorLayer(path, '', 'ogr')
self.loadVectorLayer(name, ogr_layer, external)
self.loadVectorLayer(name, ogr_layer, external=external, feedback=feedback)
else:
# already an ogr layer source
self.loadVectorLayer(name, layer, external)
# already an ogr disk based layer source
self.loadVectorLayer(name, layer, external=external, feedback=feedback)

def loadVectorLayer(self, name, layer, external=False):
def loadVectorLayer(self, name, layer, external=False, feedback=None):
"""
Creates a dedicated command to load a vector into
temporary GRASS DB.
:param name: name of the parameter
:param layer: QgsMapLayer for the vector layer.
:param external: use v.external (v.in.ogr if False).
:param feedback: feedback object
"""
# TODO: support multiple input formats
if external is None:
@@ -828,12 +829,15 @@ def loadVectorLayer(self, name, layer, external=False):

# safety check: we can only use external for ogr layers which support random read
if external:
ds = ogr.Open(layer.source())
feedback.pushInfo('Attempting to use v.external for direct layer read')
ds = ogr.Open(file_path)
if ds is not None:
ogr_layer = ds.GetLayer()
if ogr_layer is None or not ogr_layer.TestCapability(ogr.OLCRandomRead):
feedback.reportError('Cannot use v.external: layer does not support random read')
external = False
else:
feedback.reportError('Cannot use v.external: error reading layer')
external = False

self.inputLayers.append(layer)

0 comments on commit 82ac04d

Please sign in to comment.
You can’t perform that action at this time.