Skip to content

Commit

Permalink
Keep only vector layer file path when calling an OTB algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and nyalldawson committed Jan 5, 2021
1 parent 454c4f6 commit 5c19845
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions python/plugins/processing/algs/otb/OtbAlgorithm.py
Expand Up @@ -47,7 +47,8 @@
QgsProcessingParameterVectorDestination,
QgsProcessingParameterEnum,
QgsProcessingParameterBand,
QgsProcessingParameterField)
QgsProcessingParameterField,
QgsProviderRegistry)

from processing.core.parameters import getParameterFromString
from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice
Expand Down Expand Up @@ -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.