Skip to content

Commit

Permalink
Added patch for #6545
Browse files Browse the repository at this point in the history
Fixed bug in SAGA extent calculation (there was a half cellsize offset)
  • Loading branch information
volaya committed Oct 20, 2012
1 parent bb3815f commit 6546d74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions python/plugins/sextante/r/RAlgorithm.py
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/r/RUtils.py
Expand Up @@ -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()
Expand Down
21 changes: 17 additions & 4 deletions python/plugins/sextante/saga/SagaAlgorithm.py
Expand Up @@ -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
Expand All @@ -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):

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 6546d74

Please sign in to comment.