Skip to content

Commit 788407a

Browse files
committed
[processing] saga import/export optimization
1 parent 048c26a commit 788407a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

python/plugins/processing/saga/SagaAlgorithm.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def calculateResamplingExtent(self):
153153

154154

155155
def addToResamplingExtent(self, layer, first):
156+
if layer is None:
157+
return
156158
if first:
157159
self.inputExtentsCount = 1
158160
self.xmin = layer.extent().xMinimum()
@@ -304,16 +306,30 @@ def processAlgorithm(self, progress):
304306
commands.append(command)
305307

306308
#3:Export resulting raster layers
309+
optim = ProcessingConfig.getSetting(SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION)
307310
for out in self.outputs:
308311
if isinstance(out, OutputRaster):
309312
filename = out.getCompatibleFileName(self)
310313
filename2 = filename + ".sgrd"
311314
formatIndex = 1 if saga208 else 4
315+
sessionExportedLayers[filename] = filename2
316+
dontExport = True
317+
318+
#Do not export is the output is not a final output of the model
319+
if self.model is not None and optim:
320+
for subalg in self.model.algOutputs:
321+
if out.name in subalg:
322+
if subalg[out.name] is not None:
323+
dontExport = False
324+
break
325+
if dontExport:
326+
continue
327+
312328
if isWindows() or isMac() or not saga208:
313329
commands.append("io_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT " + str(formatIndex) +" -TYPE 0 -FILE \"" + filename + "\"");
314330
else:
315331
commands.append("libio_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT 1 -TYPE 0 -FILE \"" + filename + "\"");
316-
sessionExportedLayers[filename] = filename2
332+
317333

318334

319335
#4 Run SAGA

python/plugins/processing/saga/SagaAlgorithmProvider.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def initializeSettings(self):
4646
if isWindows():
4747
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_FOLDER, "SAGA folder", SagaUtils.sagaPath()))
4848
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_208, "Enable SAGA 2.0.8 compatibility", False))
49+
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION, "Enable SAGA Import/Export optimizations", False))
4950
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_AUTO_RESAMPLING, "Use min covering grid system for resampling", True))
5051
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS, "Log execution commands", True))
5152
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE, "Log console output", True))

python/plugins/processing/saga/SagaUtils.py

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class SagaUtils:
4646
SAGA_RESAMPLING_REGION_YMAX = "SAGA_RESAMPLING_REGION_YMAX"
4747
SAGA_RESAMPLING_REGION_CELLSIZE = "SAGA_RESAMPLING_REGION_CELLSIZE"
4848
SAGA_FOLDER = "SAGA_FOLDER"
49+
SAGA_IMPORT_EXPORT_OPTIMIZATION = "SAGA_IMPORT_EXPORT_OPTIMIZATION"
50+
4951

5052
@staticmethod
5153
def sagaBatchJobFilename():

0 commit comments

Comments
 (0)