Skip to content


[processing][GRASS] Give some more feedback when trying to use
Browse files Browse the repository at this point in the history
v.external for reading inputs, and if we can't, advise why not
  • Loading branch information
nyalldawson committed Nov 1, 2018
1 parent 676238b commit 82ac04d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions python/plugins/processing/algs/grass7/
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def processInputs(self, parameters, context, feedback):
paramName, parameters, context)
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)
Expand All @@ -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)


Expand Down Expand Up @@ -808,18 +808,19 @@ def loadVectorLayerFromParameter(self, name, parameters, context, feedback, exte
ogr_layer = QgsVectorLayer(path, '', 'ogr')
self.loadVectorLayer(name, ogr_layer, external)
self.loadVectorLayer(name, ogr_layer, external=external, feedback=feedback)
# 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 ( if False).
:param feedback: feedback object
# TODO: support multiple input formats
if external is None:
Expand All @@ -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
feedback.reportError('Cannot use v.external: error reading layer')
external = False

Expand Down

0 comments on commit 82ac04d

Please sign in to comment.