Skip to content

Commit 1787085

Browse files
nyalldawsonalexbruy
authored andcommittedNov 9, 2017
More followups to SAGA raster parameter handling
1 parent 1fc395b commit 1787085

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed
 

‎python/plugins/processing/algs/saga/SagaAlgorithm.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
import importlib
3131
from qgis.core import (QgsProcessingUtils,
3232
QgsProcessingException,
33-
QgsMessageLog)
33+
QgsMessageLog,
34+
QgsProcessingParameterRasterLayer,
35+
QgsProcessingParameterNumber)
3436
from processing.core.ProcessingConfig import ProcessingConfig
3537
from processing.core.parameters import (getParameterFromString,
3638
ParameterExtent,
37-
ParameterRaster,
3839
ParameterVector,
3940
ParameterTable,
4041
ParameterMultipleInput,
4142
ParameterBoolean,
4243
ParameterFixedTable,
43-
ParameterNumber,
4444
ParameterSelection)
4545
from processing.core.outputs import (getOutputFromString,
4646
OutputVector,
@@ -145,13 +145,13 @@ def processAlgorithm(self, parameters, context, feedback):
145145
# 1: Export rasters to sgrd and vectors to shp
146146
# Tables must be in dbf format. We check that.
147147
for param in self.parameterDefinitions():
148-
if isinstance(param, ParameterRaster):
148+
if isinstance(param, QgsProcessingParameterRasterLayer):
149149
if param.name() not in parameters or parameters[param.name()] is None:
150150
continue
151151
if parameters[param.name()].endswith('sdat'):
152152
parameters[param.name()] = parameters[param.name()][:-4] + "sgrd"
153153
elif not parameters[param.name()].endswith('sgrd'):
154-
exportCommand = self.exportRasterLayer(parameters[param.name()])
154+
exportCommand = self.exportRasterLayer(parameters[param.name()], context)
155155
if exportCommand is not None:
156156
commands.append(exportCommand)
157157
if isinstance(param, ParameterVector):
@@ -214,7 +214,7 @@ def processAlgorithm(self, parameters, context, feedback):
214214
for param in self.parameterDefinitions():
215215
if not param.name() in parameters or parameters[param.name()] is None:
216216
continue
217-
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
217+
if isinstance(param, (QgsProcessingParameterRasterLayer, ParameterVector, ParameterTable)):
218218
value = parameters[param.name()]
219219
if value in list(self.exportedLayers.keys()):
220220
command += ' -' + param.name() + ' "' \
@@ -249,7 +249,7 @@ def processAlgorithm(self, parameters, context, feedback):
249249
for i in range(4):
250250
command += ' -' + self.extentParamNames[i] + ' ' \
251251
+ str(float(values[i]) + offset[i])
252-
elif isinstance(param, (ParameterNumber, ParameterSelection)):
252+
elif isinstance(param, (QgsProcessingParameterNumber, ParameterSelection)):
253253
command += ' -' + param.name() + ' ' + str(param.value)
254254
else:
255255
command += ' -' + param.name() + ' "' + str(param.value) + '"'
@@ -322,9 +322,8 @@ def getOutputCellsize(self, parameters):
322322
break
323323
return cellsize
324324

325-
def exportRasterLayer(self, source):
325+
def exportRasterLayer(self, source, context):
326326
global sessionExportedLayers
327-
context = dataobjects.createContext()
328327
if source in sessionExportedLayers:
329328
exportedLayer = sessionExportedLayers[source]
330329
if os.path.exists(exportedLayer):
@@ -354,7 +353,7 @@ def checkParameterValues(self, parameters, context):
354353
extent = None
355354
for param in self.parameterDefinitions():
356355
files = []
357-
if isinstance(param, ParameterRaster):
356+
if isinstance(param, QgsProcessingParameterRasterLayer):
358357
files = [parameters[param.name()]]
359358
elif (isinstance(param, ParameterMultipleInput) and
360359
param.datatype == ParameterMultipleInput.TYPE_RASTER):

0 commit comments

Comments
 (0)
Please sign in to comment.