[processing]changed native raster format for SAGA algorithms from tif to sdat

This eliminates the need to export to a QGIS compatible format after generating a raster output. The SDAT format is the native SAGA format, and it is supported by GDAL, so it is also supported by QGIS. This was not used before, but now we use that to reduce the nuber of steps and provide a better integration.

Conversion to other formats is now done by Processing itself, not by the SAGA algorithm.

fixes #10735
This commit is contained in:
volaya 2015-06-22 09:10:01 +02:00
parent 92cf321d13
commit 32d6275fa3
3 changed files with 15 additions and 90 deletions

View File

@ -28,8 +28,8 @@ __revision__ = '$Format:%H$'
import os
import importlib
import subprocess
from PyQt4.QtGui import QIcon
from processing.gui.Help2Html import getHtmlFromRstFile
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
@ -209,51 +209,23 @@ class SagaAlgorithm212(GeoAlgorithm):
command += ' -' + param.name + ' "' + str(param.value) + '"'
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)
filename += '.sgrd'
command += ' -' + out.name + ' "' + filename + '"'
if isinstance(out, OutputVector):
filename = out.getCompatibleFileName(self)
command += ' -' + out.name + ' "' + filename + '"'
if isinstance(out, OutputTable):
filename = out.getCompatibleFileName(self)
command += ' -' + out.name + ' "' + filename + '"'
command += ' -' + out.name + ' "' + out.getCompatibleFileName(self) + '"'
commands.append(command)
# 3: Export resulting raster layers
# optim = ProcessingConfig.getSetting(SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION)
# special treatment for RGB algorithm
#TODO: improve this and put this code somewhere else
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)
filename2 = filename + '.sgrd'
formatIndex = (4 if isWindows() else 1)
sessionExportedLayers[filename] = filename2
# Do not export is the output is not a final output
# of the model
# dontExport = True
# if self.model is not None and optim:
# for subalg in self.model.algOutputs:
# if out.name in subalg:
# if subalg[out.name] is not None:
# dontExport = False
# break
# if dontExport:
# continue
if self.cmdname == 'RGB Composite':
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
+ '" -FILE:"' + filename
+ '"')
else:
commands.append('io_gdal 1 -GRIDS "' + filename2
+ '" -FORMAT ' + str(formatIndex)
+ ' -TYPE 0 -FILE "' + filename + '"')
# 4: Run SAGA
# 3: Run SAGA
commands = self.editCommands(commands)
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
loglines = []
@ -265,6 +237,7 @@ class SagaAlgorithm212(GeoAlgorithm):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
SagaUtils.executeSaga(progress)
def preProcessInputs(self):
name = self.commandLineName().replace('.', '_')[len('saga:'):]
try:

View File

@ -35,7 +35,7 @@ from processing.core.parameters import ParameterRaster, ParameterVector, Paramet
from processing.core.outputs import OutputRaster, OutputVector, OutputTable
import SagaUtils
from processing.tools import dataobjects
from processing.tools.system import getTempFilenameInTempFolder, getTempFilename, isWindows
from processing.tools.system import getTempFilename
sessionExportedLayers = {}
@ -161,50 +161,23 @@ class SagaAlgorithm213(SagaAlgorithm212):
command += ' -' + param.name + ' "' + str(param.value) + '"'
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)
filename += '.sgrd'
command += ' -' + out.name + ' "' + filename + '"'
if isinstance(out, OutputVector):
filename = out.getCompatibleFileName(self)
command += ' -' + out.name + ' "' + filename + '"'
if isinstance(out, OutputTable):
filename = out.getCompatibleFileName(self)
command += ' -' + out.name + ' "' + filename + '"'
command += ' -' + out.name + ' "' + out.getCompatibleFileName(self) + '"'
commands.append(command)
# 3: Export resulting raster layers
# optim = ProcessingConfig.getSetting( SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION)
# special treatment for RGB algorithm
#TODO: improve this and put this code somewhere else
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)
filename2 = filename + '.sgrd'
formatIndex = (4 if isWindows() else 1)
sessionExportedLayers[filename] = filename2
# Do not export is the output is not a final output
# of the model
# dontExport = True
#if self.model is not None and optim:
# for subalg in self.model.algOutputs:
# if out.name in subalg:
# if subalg[out.name] is not None:
# dontExport = False
# break
# if dontExport:
# continue
if self.cmdname == 'RGB Composite':
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
+ '" -FILE:"' + filename
+ '"')
else:
commands.append('io_gdal 1 -GRIDS "' + filename2
+ '" -FORMAT ' + str(formatIndex)
+ ' -TYPE 0 -FILE "' + filename + '"')
# 4: Run SAGA
# 3: Run SAGA
commands = self.editCommands(commands)
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
loglines = []
@ -216,25 +189,4 @@ class SagaAlgorithm213(SagaAlgorithm212):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
SagaUtils.executeSaga(progress)
def exportRasterLayer(self, source):
global sessionExportedLayers
if source in sessionExportedLayers:
exportedLayer = sessionExportedLayers[source]
if os.path.exists(exportedLayer):
self.exportedLayers[source] = exportedLayer
return None
else:
del sessionExportedLayers[source]
layer = dataobjects.getObjectFromUri(source, False)
if layer:
filename = layer.name()
else:
filename = os.path.basename(source)
validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:'
filename = ''.join(c for c in filename if c in validChars)
if len(filename) == 0:
filename = 'layer'
destFilename = getTempFilenameInTempFolder(filename + '.sgrd')
self.exportedLayers[source] = destFilename
sessionExportedLayers[source] = destFilename
return 'io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "' + destFilename + '" -FILES "' + source + '"'

View File

@ -122,7 +122,7 @@ class SagaAlgorithmProvider(AlgorithmProvider):
return ['shp']
def getSupportedOutputRasterLayerExtensions(self):
return ['tif']
return ['sdat']
def getSupportedOutputTableLayerExtensions(self):
return ['dbf']