Skip to content
Permalink
Browse files
[processing] Reduced number of conversion operation when running saga…
… algorithms
  • Loading branch information
volaya committed Sep 15, 2013
1 parent 2d101c4 commit a5f0e4b18a344068e6a1fdbab4b080b26d7cee89
@@ -65,6 +65,11 @@ def __init__(self):
self.canRunInBatchMode = True
#to be set by the provider when it loads the algorithm
self.provider = None

#if the algorithm is run as part of a model, the parent model can be set in this variable,
#to allow for customized behaviour, in case some operations should be run differently when
#running as part of a model
self.model = None

self.defineCharacteristics()

@@ -135,13 +140,14 @@ def checkParameterValuesBeforeExecuting(self):
#=========================================================


def execute(self, progress):
def execute(self, progress, model = None):

'''The method to use to call a processing algorithm.
Although the body of the algorithm is in processAlgorithm(),
it should be called using this method, since it performs
some additional operations.
Raises a GeoAlgorithmExecutionException in case anything goes wrong.'''

self.model = model
try:
self.setOutputCRS()
self.resolveTemporaryOutputs()
@@ -46,7 +46,7 @@
from processing.parameters.ParameterFactory import ParameterFactory
from processing.outputs.OutputFactory import OutputFactory
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools import dataobjects
from processing.tools import dataobjects, system
from processing.grass.GrassUtils import GrassUtils
from processing.parameters.ParameterSelection import ParameterSelection
from processing.core.WrongHelpFileException import WrongHelpFileException
@@ -55,12 +55,6 @@
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterString import ParameterString

NUM_EXPORTED = 1

def getNumExportedLayers():
NUM_EXPORTED += 1
return NUM_EXPORTED

class GrassAlgorithm(GeoAlgorithm):

GRASS_OUTPUT_TYPE_PARAMETER = "GRASS_OUTPUT_TYPE_PARAMETER"
@@ -443,7 +437,7 @@ def exportRasterLayer(self, layer):


def getTempFilename(self):
filename = "tmp" + str(time.time()).replace(".","") + str(getNumExportedLayers())
filename = "tmp" + str(time.time()).replace(".","") + str(system.getNumExportedLayers())
return filename

def commandLineName(self):
@@ -23,7 +23,8 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
import stat
import shutil
from qgis.core import QgsApplication
from PyQt4.QtCore import *
import traceback
@@ -32,8 +33,7 @@
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools.system import *
from processing.core.ProcessingLog import ProcessingLog
import stat
import shutil


class GrassUtils:

@@ -67,6 +67,12 @@ def grassScriptFilename():
filename = "grass_script.bat"
filename = userFolder() + os.sep + filename
return filename

@staticmethod
def getGrassVersion():
#I do not know if this should be removed or let the user enter it
#or something like that... This is just a temporary thing
return "6.4.0"

@staticmethod
def grassPath():
@@ -23,7 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from qgis.core import *
from processing.parameters.ParameterMultipleInput import ParameterMultipleInput
from processing.grass.GrassUtils import GrassUtils
@@ -34,7 +33,6 @@
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterRaster import ParameterRaster
from processing.tools import dataobjects
import time

class nviz(GeoAlgorithm):

@@ -16,8 +16,7 @@
* *
***************************************************************************
"""
from processing.tools.vector import features
from processing.core.ProcessingLog import ProcessingLog


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -31,6 +30,8 @@
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.tools import dataobjects
from processing.tools.system import *
from processing.tools import vector
from processing.core.ProcessingLog import ProcessingLog
from processing.gui.Postprocessing import Postprocessing
from processing.core.SilentProgress import SilentProgress
import traceback
@@ -65,7 +66,7 @@ def runalgIterating(alg,paramToIter,progress):
filelist = []
outputs = {}
provider = layer.dataProvider()
features = features(layer)
features = vector.features(layer)
for feat in features:
output = getTempFilename("shp")
filelist.append(output)
@@ -51,6 +51,8 @@
from processing.parameters.ParameterFixedTable import ParameterFixedTable
from processing.core.ProcessingLog import ProcessingLog

sessionExportedLayers = {}

class SagaAlgorithm(GeoAlgorithm):

OUTPUT_EXTENT = "OUTPUT_EXTENT"
@@ -193,7 +195,9 @@ def processAlgorithm(self, progress):
continue
value = param.value
if not value.endswith("sgrd"):
commands.append(self.exportRasterLayer(value))
exportCommand = self.exportRasterLayer(value)
if exportCommand is not None:
commands.append(exportCommand)
if self.resample:
commands.append(self.resampleRasterLayer(value));
if isinstance(param, ParameterVector):
@@ -309,6 +313,7 @@ def processAlgorithm(self, progress):
commands.append("io_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT " + str(formatIndex) +" -TYPE 0 -FILE \"" + filename + "\"");
else:
commands.append("libio_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT 1 -TYPE 0 -FILE \"" + filename + "\"");
sessionExportedLayers[filename] = filename2


#4 Run SAGA
@@ -377,6 +382,9 @@ def resampleRasterLayer(self,layer):


def exportRasterLayer(self, source):
if source in sessionExportedLayers:
self.exportedLayers[source] = sessionExportedLayers[source]
return None
layer = dataobjects.getObjectFromUri(source, False)
if layer:
filename = str(layer.name())
@@ -388,15 +396,13 @@ def exportRasterLayer(self, source):
filename = "layer"
destFilename = getTempFilenameInTempFolder(filename + ".sgrd")
self.exportedLayers[source]= destFilename
sessionExportedLayers[source] = destFilename
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
if isWindows() or isMac() or not saga208:
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + source+"\""
else:
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + source + "\""




def checkBeforeOpeningParametersDialog(self):
msg = SagaUtils.checkSagaIsInstalled()
if msg is not None:
@@ -77,11 +77,12 @@ def removeInvalidChars(string):
return string


NUM_EXPORTED = 1
numExported = 1

def getNumExportedLayers():
NUM_EXPORTED += 1
return NUM_EXPORTED
global numExported
numExported += 1
return numExported

def mkdir(newdir):
if os.path.isdir(newdir):

0 comments on commit a5f0e4b

Please sign in to comment.