Skip to content
Permalink
Browse files

Keep only vector layer file path when calling an OTB algorithm

  • Loading branch information
troopa81 authored and nyalldawson committed Jan 5, 2021
1 parent 454c4f6 commit 5c19845d32a955070c9b3cacd567b78dc636d8c0
Showing with 14 additions and 2 deletions.
  1. +14 −2 python/plugins/processing/algs/otb/OtbAlgorithm.py
@@ -47,7 +47,8 @@
QgsProcessingParameterVectorDestination,
QgsProcessingParameterEnum,
QgsProcessingParameterBand,
QgsProcessingParameterField)
QgsProcessingParameterField,
QgsProviderRegistry)

from processing.core.parameters import getParameterFromString
from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice
@@ -283,9 +284,20 @@ def processAlgorithm(self, parameters, context, feedback):

def getLayerSource(self, name, layer):
providerName = layer.dataProvider().name()

# TODO: add other provider support in OTB, eg: memory
if providerName in ['ogr', 'gdal']:
if providerName == 'gdal':
return layer.source()
elif providerName == 'ogr':
# when a file contains several layer we pass only the file path to OTB
# TODO make OTB able to take a layer index in this case
uriElements = QgsProviderRegistry.instance().decodeUri("ogr", layer.source())

if 'path' not in uriElements:
raise QgsProcessingException(
self.tr("Invalid layer source '{}'. Missing valid 'path' element".format(layer.source())))

return uriElements['path']
else:
raise QgsProcessingException(
self.tr("OTB currently support only gdal and ogr provider. Parameter '{}' uses '{}' provider".format(name, providerName)))

0 comments on commit 5c19845

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