Skip to content
Permalink
Browse files

Added patch for #6545

Fixed bug in SAGA extent calculation (there was a half cellsize offset)
  • Loading branch information
volaya committed Oct 20, 2012
1 parent bb3815f commit 6546d748c83236c78fe8cebdcb7123443ef16112
@@ -96,7 +96,7 @@ def defineCharacteristicsFromFile(self):
self.name = filename[:filename.rfind(".")].replace("_", " ")
self.group = "User R scripts"
lines = open(self.descriptionFile)
line = lines.readline().strip("\n")
line = lines.readline().strip("\n").strip("\r")
while line != "":
if line.startswith("##"):
try:
@@ -112,7 +112,7 @@ def defineCharacteristicsFromFile(self):
else:
self.commands.append(line)
self.script += line + "\n"
line = lines.readline().strip("\n")
line = lines.readline().strip("\n").strip("\r")
lines.close()

def getVerboseCommands(self):
@@ -82,7 +82,7 @@ def executeRAlgorithm(alg, progress):
os.chmod(RUtils.getRScriptFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
command = "R CMD BATCH --vanilla " + RUtils.getRScriptFilename() + " "+ RUtils.getConsoleOutputFilename()

proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT,
proc = subprocess.Popen(command, shell=SextanteUtils.isWindows(), stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT,
universal_newlines=True)
proc.wait()
RUtils.createConsoleOutput()
@@ -40,11 +40,9 @@
from sextante.saga.SagaUtils import SagaUtils
from sextante.saga.SagaGroupNameDecorator import SagaGroupNameDecorator
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.SextanteLog import SextanteLog
from sextante.parameters.ParameterFactory import ParameterFactory
from sextante.outputs.OutputFactory import OutputFactory
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.SextanteLog import SextanteLog
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterSelection import ParameterSelection
@@ -53,6 +51,7 @@
from sextante.parameters.ParameterExtent import ParameterExtent
from PyQt4 import QtGui
from sextante.parameters.ParameterFixedTable import ParameterFixedTable
from sextante.core.SextanteLog import SextanteLog

class SagaAlgorithm(GeoAlgorithm):

@@ -264,9 +263,12 @@ def processAlgorithm(self, progress):
f.close()
command+=( " -" + param.name + " " + tempTableFile)
elif isinstance(param, ParameterExtent):
#'we have to substract half cell size, since saga is center based, not corner based
halfcell = self.getOutputCellsize() / 2
offset = [halfcell, 0, halfcell, 0]
values = param.value.split(",")
for i in range(4):
command+=(" -" + self.extentParamNames[i] + " " + str(values[i]));
command+=(" -" + self.extentParamNames[i] + " " + str(float(values[i]) + offset[i]));
elif isinstance(param, (ParameterNumber, ParameterSelection)):
command+=(" -" + param.name + " " + str(param.value));
else:
@@ -316,7 +318,18 @@ def processAlgorithm(self, progress):
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
SagaUtils.executeSaga(progress);



def getOutputCellsize(self):
'''tries to guess the cellsize of the output, searchiing for a parameter with an appropriate name for it'''
cellsize = 0;
for param in self.parameters:
if param.value is not None and param.name == "USER_SIZE":
cellsize = float(param.value)
break;
QtGui.QMessageBox.critical(None, "", str(cellsize));
return cellsize


def resampleRasterLayer(self,layer):
'''this is supposed to be run after having exported all raster layers'''
if layer in self.exportedLayers.keys():

0 comments on commit 6546d74

Please sign in to comment.
You can’t perform that action at this time.