Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] saga import/export optimization
  • Loading branch information
volaya committed Sep 15, 2013
1 parent 048c26a commit 788407a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion python/plugins/processing/saga/SagaAlgorithm.py
Expand Up @@ -153,6 +153,8 @@ def calculateResamplingExtent(self):


def addToResamplingExtent(self, layer, first):
if layer is None:
return
if first:
self.inputExtentsCount = 1
self.xmin = layer.extent().xMinimum()
Expand Down Expand Up @@ -304,16 +306,30 @@ def processAlgorithm(self, progress):
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
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/saga/SagaAlgorithmProvider.py
Expand Up @@ -46,6 +46,7 @@ def initializeSettings(self):
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))
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/saga/SagaUtils.py
Expand Up @@ -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():
Expand Down

0 comments on commit 788407a

Please sign in to comment.