Skip to content

Commit 32d6275

Browse files
committedJun 22, 2015
[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
1 parent 92cf321 commit 32d6275

File tree

3 files changed

+15
-90
lines changed

3 files changed

+15
-90
lines changed
 

‎python/plugins/processing/algs/saga/SagaAlgorithm212.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
import os
3030
import importlib
31+
import subprocess
3132
from PyQt4.QtGui import QIcon
32-
from processing.gui.Help2Html import getHtmlFromRstFile
3333
from processing.core.GeoAlgorithm import GeoAlgorithm
3434
from processing.core.ProcessingConfig import ProcessingConfig
3535
from processing.core.ProcessingLog import ProcessingLog
@@ -209,51 +209,23 @@ def processAlgorithm(self, progress):
209209
command += ' -' + param.name + ' "' + str(param.value) + '"'
210210

211211
for out in self.outputs:
212-
if isinstance(out, OutputRaster):
213-
filename = out.getCompatibleFileName(self)
214-
filename += '.sgrd'
215-
command += ' -' + out.name + ' "' + filename + '"'
216-
if isinstance(out, OutputVector):
217-
filename = out.getCompatibleFileName(self)
218-
command += ' -' + out.name + ' "' + filename + '"'
219-
if isinstance(out, OutputTable):
220-
filename = out.getCompatibleFileName(self)
221-
command += ' -' + out.name + ' "' + filename + '"'
212+
command += ' -' + out.name + ' "' + out.getCompatibleFileName(self) + '"'
222213

223214
commands.append(command)
224215

225-
# 3: Export resulting raster layers
226-
# optim = ProcessingConfig.getSetting(SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION)
216+
217+
# special treatment for RGB algorithm
218+
#TODO: improve this and put this code somewhere else
227219
for out in self.outputs:
228220
if isinstance(out, OutputRaster):
229221
filename = out.getCompatibleFileName(self)
230222
filename2 = filename + '.sgrd'
231-
formatIndex = (4 if isWindows() else 1)
232-
sessionExportedLayers[filename] = filename2
233-
234-
# Do not export is the output is not a final output
235-
# of the model
236-
# dontExport = True
237-
# if self.model is not None and optim:
238-
# for subalg in self.model.algOutputs:
239-
# if out.name in subalg:
240-
# if subalg[out.name] is not None:
241-
# dontExport = False
242-
# break
243-
# if dontExport:
244-
# continue
245-
246223
if self.cmdname == 'RGB Composite':
247224
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
248225
+ '" -FILE:"' + filename
249226
+ '"')
250-
else:
251-
commands.append('io_gdal 1 -GRIDS "' + filename2
252-
+ '" -FORMAT ' + str(formatIndex)
253-
+ ' -TYPE 0 -FILE "' + filename + '"')
254-
255227

256-
# 4: Run SAGA
228+
# 3: Run SAGA
257229
commands = self.editCommands(commands)
258230
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
259231
loglines = []
@@ -265,6 +237,7 @@ def processAlgorithm(self, progress):
265237
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
266238
SagaUtils.executeSaga(progress)
267239

240+
268241
def preProcessInputs(self):
269242
name = self.commandLineName().replace('.', '_')[len('saga:'):]
270243
try:
@@ -352,4 +325,4 @@ def checkParameterValuesBeforeExecuting(self):
352325
if extent != extent2:
353326
return self.tr("Input layers do not have the same grid extent.")
354327

355-
328+

‎python/plugins/processing/algs/saga/SagaAlgorithm213.py

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from processing.core.outputs import OutputRaster, OutputVector, OutputTable
3636
import SagaUtils
3737
from processing.tools import dataobjects
38-
from processing.tools.system import getTempFilenameInTempFolder, getTempFilename, isWindows
38+
from processing.tools.system import getTempFilename
3939

4040
sessionExportedLayers = {}
4141

@@ -161,50 +161,23 @@ def processAlgorithm(self, progress):
161161
command += ' -' + param.name + ' "' + str(param.value) + '"'
162162

163163
for out in self.outputs:
164-
if isinstance(out, OutputRaster):
165-
filename = out.getCompatibleFileName(self)
166-
filename += '.sgrd'
167-
command += ' -' + out.name + ' "' + filename + '"'
168-
if isinstance(out, OutputVector):
169-
filename = out.getCompatibleFileName(self)
170-
command += ' -' + out.name + ' "' + filename + '"'
171-
if isinstance(out, OutputTable):
172-
filename = out.getCompatibleFileName(self)
173-
command += ' -' + out.name + ' "' + filename + '"'
164+
command += ' -' + out.name + ' "' + out.getCompatibleFileName(self) + '"'
174165

175166
commands.append(command)
176167

177-
# 3: Export resulting raster layers
178-
# optim = ProcessingConfig.getSetting( SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION)
168+
# special treatment for RGB algorithm
169+
#TODO: improve this and put this code somewhere else
179170
for out in self.outputs:
180171
if isinstance(out, OutputRaster):
181172
filename = out.getCompatibleFileName(self)
182173
filename2 = filename + '.sgrd'
183-
formatIndex = (4 if isWindows() else 1)
184-
sessionExportedLayers[filename] = filename2
185-
# Do not export is the output is not a final output
186-
# of the model
187-
# dontExport = True
188-
#if self.model is not None and optim:
189-
# for subalg in self.model.algOutputs:
190-
# if out.name in subalg:
191-
# if subalg[out.name] is not None:
192-
# dontExport = False
193-
# break
194-
# if dontExport:
195-
# continue
196-
197174
if self.cmdname == 'RGB Composite':
198175
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
199176
+ '" -FILE:"' + filename
200177
+ '"')
201-
else:
202-
commands.append('io_gdal 1 -GRIDS "' + filename2
203-
+ '" -FORMAT ' + str(formatIndex)
204-
+ ' -TYPE 0 -FILE "' + filename + '"')
205178

206179

207-
# 4: Run SAGA
180+
# 3: Run SAGA
208181
commands = self.editCommands(commands)
209182
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
210183
loglines = []
@@ -216,25 +189,4 @@ def processAlgorithm(self, progress):
216189
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
217190
SagaUtils.executeSaga(progress)
218191

219-
def exportRasterLayer(self, source):
220-
global sessionExportedLayers
221-
if source in sessionExportedLayers:
222-
exportedLayer = sessionExportedLayers[source]
223-
if os.path.exists(exportedLayer):
224-
self.exportedLayers[source] = exportedLayer
225-
return None
226-
else:
227-
del sessionExportedLayers[source]
228-
layer = dataobjects.getObjectFromUri(source, False)
229-
if layer:
230-
filename = layer.name()
231-
else:
232-
filename = os.path.basename(source)
233-
validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:'
234-
filename = ''.join(c for c in filename if c in validChars)
235-
if len(filename) == 0:
236-
filename = 'layer'
237-
destFilename = getTempFilenameInTempFolder(filename + '.sgrd')
238-
self.exportedLayers[source] = destFilename
239-
sessionExportedLayers[source] = destFilename
240-
return 'io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "' + destFilename + '" -FILES "' + source + '"'
192+

‎python/plugins/processing/algs/saga/SagaAlgorithmProvider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def getSupportedOutputVectorLayerExtensions(self):
122122
return ['shp']
123123

124124
def getSupportedOutputRasterLayerExtensions(self):
125-
return ['tif']
125+
return ['sdat']
126126

127127
def getSupportedOutputTableLayerExtensions(self):
128128
return ['dbf']

0 commit comments

Comments
 (0)
Please sign in to comment.