Skip to content
Permalink
Browse files
[processing] rewrote saga raster calculator as individual algorithm
  • Loading branch information
volaya committed May 21, 2014
1 parent b1103c0 commit fad280edd0a78e22c16fc69613b1716264b66bb1
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
RasterCalculator.py
---------------------
Date : May 2014
Copyright : (C) 2014 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
from processing.parameters.ParameterMultipleInput import ParameterMultipleInput
from processing.algs.saga.SagaAlgorithm import SagaAlgorithm
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.parameters.ParameterString import ParameterString
from processing.algs.saga.SagaGroupNameDecorator import SagaGroupNameDecorator

__author__ = 'Victor Olaya'
__date__ = 'May 2014'
__copyright__ = '(C) 2014, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from PyQt4 import QtGui
from processing.parameters.ParameterRaster import ParameterRaster
from processing.outputs.OutputRaster import OutputRaster
from processing.tools.system import *


class RasterCalculator(SagaAlgorithm):


FORMULA = "FORMULA"
GRIDS = 'GRIDS'
XGRIDS = 'XGRIDS'
RESULT = "RESULT"

def __init__(self):
self.allowUnmatchingGridExtents = True
self.hardcodedStrings = []
GeoAlgorithm.__init__(self)

def getCopy(self):
newone = RasterCalculator()
newone.provider = self.provider
return newone

def defineCharacteristics(self):
self.name = 'Raster calculator'
self.cmdname = 'Grid Calculator'
self.undecoratedGroup = "grid_calculus"
self.group = SagaGroupNameDecorator.getDecoratedName(self.undecoratedGroup)
grids = ParameterRaster(self.GRIDS, 'Input layers', True)
grids.hidden = True
self.addParameter(grids)
self.addParameter(ParameterMultipleInput(self.XGRIDS, 'Input layers',
ParameterMultipleInput.TYPE_RASTER, False))
self.addParameter(ParameterString(self.FORMULA, "Formula"))
self.addOutput(OutputRaster(self.RESULT, "Result"))


def processAlgorithm(self, progress):
xgrids = self.getParameterValue(self.XGRIDS)
layers = xgrids.split(';')
grid = layers[0]
self.setParameterValue(self.GRIDS, grid)
xgrids = ";".join(layers[1:])
if xgrids == "": xgrids = None
self.setParameterValue(self.XGRIDS, xgrids)
SagaAlgorithm.processAlgorithm(self, progress)
@@ -62,11 +62,10 @@ class SagaAlgorithm(GeoAlgorithm):

OUTPUT_EXTENT = 'OUTPUT_EXTENT'

def __init__(self, descriptionfile):
self.allowUnmatchingGridExtents = False

# In case several non-matching raster layers are used as input
def __init__(self, descriptionfile):
GeoAlgorithm.__init__(self)
self.hardcodedStrings = []
self.allowUnmatchingGridExtents = False
self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()

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

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


def exportRasterLayer(self, source):
global sessionExportedLayers
if source in sessionExportedLayers:
self.exportedLayers[source] = sessionExportedLayers[source]
return None
@@ -33,6 +33,7 @@
from processing.core.ProcessingLog import ProcessingLog
from SagaAlgorithm import SagaAlgorithm
from SplitRGBBands import SplitRGBBands
from RasterCalculator import RasterCalculator
from SagaUtils import SagaUtils
from processing.tools.system import *

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

def getDescription(self):
return 'SAGA'
@@ -3,9 +3,9 @@ ta_hydrology
ParameterRaster|DEM|Elevation|False
ParameterSelection|METHOD|Flow Split Method|[0] flow width (original);[1] cell area
Harcoded|-B_SLOPE
Harcoded|B_ASPECT
Harcoded|B_AREA
Harcoded|B_FLOW
Harcoded|-B_ASPECT
Harcoded|-B_AREA
Harcoded|-B_FLOW
OutputRaster|G_SLOPE|Slope
OutputRaster|G_ASPECT|Aspect
OutputRaster|G_AREA|Flow Accumulation

This file was deleted.

0 comments on commit fad280e

Please sign in to comment.