本文整理匯總了Python中sextante.saga.SagaUtils.SagaUtils.createSagaBatchJobFileFromSagaCommands方法的典型用法代碼示例。如果您正苦於以下問題:Python SagaUtils.createSagaBatchJobFileFromSagaCommands方法的具體用法?Python SagaUtils.createSagaBatchJobFileFromSagaCommands怎麽用?Python SagaUtils.createSagaBatchJobFileFromSagaCommands使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sextante.saga.SagaUtils.SagaUtils
的用法示例。
在下文中一共展示了SagaUtils.createSagaBatchJobFileFromSagaCommands方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: processAlgorithm
# 需要導入模塊: from sextante.saga.SagaUtils import SagaUtils [as 別名]
# 或者: from sextante.saga.SagaUtils.SagaUtils import createSagaBatchJobFileFromSagaCommands [as 別名]
def processAlgorithm(self, progress):
#TODO:check correct num of bands
input = self.getParameterValue(SplitRGBBands.INPUT)
temp = SextanteUtils.getTempFilename(None).replace('.','');
basename = os.path.basename(temp)
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeBasename = ''.join(c for c in basename if c in validChars)
temp = os.path.join(os.path.dirname(temp), safeBasename)
r = self.getOutputValue(SplitRGBBands.R)
g = self.getOutputValue(SplitRGBBands.G)
b = self.getOutputValue(SplitRGBBands.B)
commands = []
if SextanteUtils.isWindows():
commands.append("io_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input+"\"")
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");
else:
commands.append("libio_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input + "\"")
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
SagaUtils.executeSaga(progress);
示例2: processAlgorithm
# 需要導入模塊: from sextante.saga.SagaUtils import SagaUtils [as 別名]
# 或者: from sextante.saga.SagaUtils.SagaUtils import createSagaBatchJobFileFromSagaCommands [as 別名]
def processAlgorithm(self, progress):
#TODO:check correct num of bands
input = self.getParameterValue(SplitRGBBands.INPUT)
temp = SextanteUtils.getTempFilename();
r = self.getOutputValue(SplitRGBBands.R)
g = self.getOutputValue(SplitRGBBands.G)
b = self.getOutputValue(SplitRGBBands.B)
commands = []
if SextanteUtils.isWindows():
commands.append("io_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input+"\"")
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");
else:
commands.append("libio_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input + "\"")
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
SagaUtils.executeSaga(progress);
示例3: processAlgorithm
# 需要導入模塊: from sextante.saga.SagaUtils import SagaUtils [as 別名]
# 或者: from sextante.saga.SagaUtils.SagaUtils import createSagaBatchJobFileFromSagaCommands [as 別名]
#.........這裏部分代碼省略.........
if layer:
filename = LayerExporter.exportVectorLayer(layer)
self.exportedLayers[layerfile]=filename
elif (not layerfile.endswith("shp")):
raise GeoAlgorithmExecutionException("Unsupported file format")
#2: set parameters and outputs
if SextanteUtils.isWindows():
command = self.undecoratedGroup + " \"" + self.cmdname + "\""
else:
command = "lib" + self.undecoratedGroup + " \"" + self.cmdname + "\""
for param in self.parameters:
if param.value is None:
continue
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
value = param.value
if value in self.exportedLayers.keys():
command+=(" -" + param.name + " \"" + self.exportedLayers[value] + "\"")
else:
command+=(" -" + param.name + " \"" + value + "\"")
elif isinstance(param, ParameterMultipleInput):
s = param.value
for layer in self.exportedLayers.keys():
s = s.replace(layer, self.exportedLayers[layer])
command+=(" -" + param.name + " \"" + s + "\"");
elif isinstance(param, ParameterBoolean):
if param.value:
command+=(" -" + param.name);
elif isinstance(param, ParameterFixedTable):
tempTableFile = SextanteUtils.getTempFilename("txt")
f = open(tempTableFile, "w")
f.write('\t'.join([col for col in param.cols]) + "\n")
values = param.value.split(",")
for i in range(0, len(values), 3):
s = values[i] + "\t" + values[i+1] + "\t" + values[i+2] + "\n"
f.write(s)
f.close()
command+=( " -" + param.name + " \"" + tempTableFile + "\"")
elif isinstance(param, ParameterExtent):
#'we have to substract/add half cell size, since saga is center based, not corner based
halfcell = self.getOutputCellsize() / 2
offset = [halfcell, -halfcell, halfcell, -halfcell]
values = param.value.split(",")
for i in range(4):
command+=(" -" + self.extentParamNames[i] + " " + str(float(values[i]) + offset[i]));
elif isinstance(param, (ParameterNumber, ParameterSelection)):
command+=(" -" + param.name + " " + str(param.value));
else:
command+=(" -" + param.name + " \"" + str(param.value) + "\"");
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)#filename = out.value
#===============================================================
# if not filename.endswith(".tif"):
# filename += ".tif"
# out.value = filename
#===============================================================
filename = SextanteUtils.tempFolder() + os.sep + os.path.basename(filename) + ".sgrd"
command+=(" -" + out.name + " \"" + filename + "\"");
if isinstance(out, OutputVector):
filename = out.getCompatibleFileName(self)#out.value
#===============================================================
# if not filename.endswith(".shp"):
# filename += ".shp"
# out.value = filename
#===============================================================
command+=(" -" + out.name + " \"" + filename + "\"");
if isinstance(out, OutputTable):
filename = out.getCompatibleFileName(self)#out.value
#===============================================================
# if not filename.endswith(".dbf"):
# filename += ".dbf"
# out.value = filename
#===============================================================
command+=(" -" + out.name + " \"" + filename + "\"");
commands.append(command)
#3:Export resulting raster layers
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)
filename2 = SextanteUtils.tempFolder() + os.sep + os.path.basename(filename) + ".sgrd"
if SextanteUtils.isWindows():
commands.append("io_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT 1 -TYPE 0 -FILE \"" + filename + "\"");
else:
commands.append("libio_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT 1 -TYPE 0 -FILE \"" + filename + "\"");
#4 Run SAGA
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
loglines = []
loglines.append("SAGA execution commands")
for line in commands:
progress.setCommand(line)
loglines.append(line)
if SextanteConfig.getSetting(SagaUtils.SAGA_LOG_COMMANDS):
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
SagaUtils.executeSaga(progress);