Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] allow using layer names as input values
  • Loading branch information
volaya committed Jul 3, 2015
1 parent 12736ac commit 2083d6d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -38,7 +38,7 @@
from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterRaster, ParameterVector, ParameterMultipleInput, Parameter
from processing.core.parameters import ParameterRaster, ParameterVector, ParameterMultipleInput, ParameterTable, Parameter
from processing.core.outputs import OutputVector, OutputRaster, OutputTable, OutputHTML, Output
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools import dataobjects, vector
Expand Down Expand Up @@ -222,6 +222,7 @@ def execute(self, progress=None, model=None):
try:
self.setOutputCRS()
self.resolveTemporaryOutputs()
self.resolveDataObjects()
self.checkOutputFileExtensions()
self.runPreExecutionScript(progress)
self.processAlgorithm(progress)
Expand Down Expand Up @@ -256,7 +257,7 @@ def _checkParameterValuesBeforeExecuting(self):
else:
inputlayers = [param.value]
for inputlayer in inputlayers:
obj = dataobjects.getObjectFromUri(inputlayer)
obj = dataobjects.getObject(inputlayer)
if obj is None:
return "Wrong parameter value: " + param.value
return self.checkParameterValuesBeforeExecuting()
Expand Down Expand Up @@ -421,6 +422,23 @@ def setOutputCRS(self):
except:
pass

def resolveDataObjects(self):
layers = dataobjects.getAllLayers()
for param in self.parameters:
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable,
ParameterMultipleInput)):
if param.value:
if isinstance(param, ParameterMultipleInput):
inputlayers = param.value.split(';')
else:
inputlayers = [param.value]
for i, inputlayer in enumerate(inputlayers):
for layer in layers:
if layer.name() == inputlayer:
inputlayers[i] = layer.source()
break
param.setValue(",".join(inputlayers))


def checkInputCRS(self):
"""It checks that all input layers use the same CRS. If so,
Expand Down

0 comments on commit 2083d6d

Please sign in to comment.