diff --git a/python/plugins/processing/saga/SagaAlgorithm.py b/python/plugins/processing/saga/SagaAlgorithm.py index 6ac058c7a74..825caaf7126 100644 --- a/python/plugins/processing/saga/SagaAlgorithm.py +++ b/python/plugins/processing/saga/SagaAlgorithm.py @@ -153,6 +153,8 @@ class SagaAlgorithm(GeoAlgorithm): def addToResamplingExtent(self, layer, first): + if layer is None: + return if first: self.inputExtentsCount = 1 self.xmin = layer.extent().xMinimum() @@ -304,16 +306,30 @@ class SagaAlgorithm(GeoAlgorithm): commands.append(command) #3:Export resulting raster layers + optim = ProcessingConfig.getSetting(SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION) for out in self.outputs: if isinstance(out, OutputRaster): filename = out.getCompatibleFileName(self) filename2 = filename + ".sgrd" formatIndex = 1 if saga208 else 4 + sessionExportedLayers[filename] = filename2 + dontExport = True + + #Do not export is the output is not a final output of the model + 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 isWindows() or isMac() or not saga208: 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 diff --git a/python/plugins/processing/saga/SagaAlgorithmProvider.py b/python/plugins/processing/saga/SagaAlgorithmProvider.py index 0bc90cabacd..aedcab929a0 100644 --- a/python/plugins/processing/saga/SagaAlgorithmProvider.py +++ b/python/plugins/processing/saga/SagaAlgorithmProvider.py @@ -46,6 +46,7 @@ class SagaAlgorithmProvider(AlgorithmProvider): if isWindows(): ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_FOLDER, "SAGA folder", SagaUtils.sagaPath())) ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_208, "Enable SAGA 2.0.8 compatibility", False)) + ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION, "Enable SAGA Import/Export optimizations", False)) ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_AUTO_RESAMPLING, "Use min covering grid system for resampling", True)) ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS, "Log execution commands", True)) ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE, "Log console output", True)) diff --git a/python/plugins/processing/saga/SagaUtils.py b/python/plugins/processing/saga/SagaUtils.py index 35397217ded..ec7d561a5a3 100644 --- a/python/plugins/processing/saga/SagaUtils.py +++ b/python/plugins/processing/saga/SagaUtils.py @@ -46,6 +46,8 @@ class SagaUtils: SAGA_RESAMPLING_REGION_YMAX = "SAGA_RESAMPLING_REGION_YMAX" SAGA_RESAMPLING_REGION_CELLSIZE = "SAGA_RESAMPLING_REGION_CELLSIZE" SAGA_FOLDER = "SAGA_FOLDER" + SAGA_IMPORT_EXPORT_OPTIMIZATION = "SAGA_IMPORT_EXPORT_OPTIMIZATION" + @staticmethod def sagaBatchJobFilename():