Skip to content

Commit fad280e

Browse files
committed
[processing] rewrote saga raster calculator as individual algorithm
1 parent b1103c0 commit fad280e

File tree

5 files changed

+89
-15
lines changed

5 files changed

+89
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
RasterCalculator.py
6+
---------------------
7+
Date : May 2014
8+
Copyright : (C) 2014 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
from processing.parameters.ParameterMultipleInput import ParameterMultipleInput
20+
from processing.algs.saga.SagaAlgorithm import SagaAlgorithm
21+
from processing.core.GeoAlgorithm import GeoAlgorithm
22+
from processing.parameters.ParameterString import ParameterString
23+
from processing.algs.saga.SagaGroupNameDecorator import SagaGroupNameDecorator
24+
25+
__author__ = 'Victor Olaya'
26+
__date__ = 'May 2014'
27+
__copyright__ = '(C) 2014, Victor Olaya'
28+
29+
# This will get replaced with a git SHA1 when you do a git archive
30+
31+
__revision__ = '$Format:%H$'
32+
33+
from PyQt4 import QtGui
34+
from processing.parameters.ParameterRaster import ParameterRaster
35+
from processing.outputs.OutputRaster import OutputRaster
36+
from processing.tools.system import *
37+
38+
39+
class RasterCalculator(SagaAlgorithm):
40+
41+
42+
FORMULA = "FORMULA"
43+
GRIDS = 'GRIDS'
44+
XGRIDS = 'XGRIDS'
45+
RESULT = "RESULT"
46+
47+
def __init__(self):
48+
self.allowUnmatchingGridExtents = True
49+
self.hardcodedStrings = []
50+
GeoAlgorithm.__init__(self)
51+
52+
def getCopy(self):
53+
newone = RasterCalculator()
54+
newone.provider = self.provider
55+
return newone
56+
57+
def defineCharacteristics(self):
58+
self.name = 'Raster calculator'
59+
self.cmdname = 'Grid Calculator'
60+
self.undecoratedGroup = "grid_calculus"
61+
self.group = SagaGroupNameDecorator.getDecoratedName(self.undecoratedGroup)
62+
grids = ParameterRaster(self.GRIDS, 'Input layers', True)
63+
grids.hidden = True
64+
self.addParameter(grids)
65+
self.addParameter(ParameterMultipleInput(self.XGRIDS, 'Input layers',
66+
ParameterMultipleInput.TYPE_RASTER, False))
67+
self.addParameter(ParameterString(self.FORMULA, "Formula"))
68+
self.addOutput(OutputRaster(self.RESULT, "Result"))
69+
70+
71+
def processAlgorithm(self, progress):
72+
xgrids = self.getParameterValue(self.XGRIDS)
73+
layers = xgrids.split(';')
74+
grid = layers[0]
75+
self.setParameterValue(self.GRIDS, grid)
76+
xgrids = ";".join(layers[1:])
77+
if xgrids == "": xgrids = None
78+
self.setParameterValue(self.XGRIDS, xgrids)
79+
SagaAlgorithm.processAlgorithm(self, progress)

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ class SagaAlgorithm(GeoAlgorithm):
6262

6363
OUTPUT_EXTENT = 'OUTPUT_EXTENT'
6464

65-
def __init__(self, descriptionfile):
66-
self.allowUnmatchingGridExtents = False
67-
68-
# In case several non-matching raster layers are used as input
65+
def __init__(self, descriptionfile):
6966
GeoAlgorithm.__init__(self)
67+
self.hardcodedStrings = []
68+
self.allowUnmatchingGridExtents = False
7069
self.descriptionFile = descriptionfile
7170
self.defineCharacteristicsFromFile()
7271

@@ -78,8 +77,7 @@ def getCopy(self):
7877
def getIcon(self):
7978
return QIcon(os.path.dirname(__file__) + '/../../images/saga.png')
8079

81-
def defineCharacteristicsFromFile(self):
82-
self.hardcodedStrings = []
80+
def defineCharacteristicsFromFile(self):
8381
lines = open(self.descriptionFile)
8482
line = lines.readline().strip('\n').strip()
8583
self.name = line
@@ -336,6 +334,7 @@ def getOutputCellsize(self):
336334

337335

338336
def exportRasterLayer(self, source):
337+
global sessionExportedLayers
339338
if source in sessionExportedLayers:
340339
self.exportedLayers[source] = sessionExportedLayers[source]
341340
return None

python/plugins/processing/algs/saga/SagaAlgorithmProvider.py

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from processing.core.ProcessingLog import ProcessingLog
3434
from SagaAlgorithm import SagaAlgorithm
3535
from SplitRGBBands import SplitRGBBands
36+
from RasterCalculator import RasterCalculator
3637
from SagaUtils import SagaUtils
3738
from processing.tools.system import *
3839

@@ -96,6 +97,7 @@ def _loadAlgorithms(self):
9697
'Could not open SAGA algorithm: '
9798
+ descriptionFile + '\n' + str(e))
9899
self.algs.append(SplitRGBBands())
100+
self.algs.append(RasterCalculator())
99101

100102
def getDescription(self):
101103
return 'SAGA'

python/plugins/processing/algs/saga/description/CatchmentArea(Mass-FluxMethod).txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ ta_hydrology
33
ParameterRaster|DEM|Elevation|False
44
ParameterSelection|METHOD|Flow Split Method|[0] flow width (original);[1] cell area
55
Harcoded|-B_SLOPE
6-
Harcoded|B_ASPECT
7-
Harcoded|B_AREA
8-
Harcoded|B_FLOW
6+
Harcoded|-B_ASPECT
7+
Harcoded|-B_AREA
8+
Harcoded|-B_FLOW
99
OutputRaster|G_SLOPE|Slope
1010
OutputRaster|G_ASPECT|Aspect
1111
OutputRaster|G_AREA|Flow Accumulation

python/plugins/processing/algs/saga/description/GridCalculator.txt

-6
This file was deleted.

0 commit comments

Comments
 (0)