本文整理汇总了Python中Grass7Utils.Grass7Utils.executeGrass7方法的典型用法代码示例。如果您正苦于以下问题:Python Grass7Utils.executeGrass7方法的具体用法?Python Grass7Utils.executeGrass7怎么用?Python Grass7Utils.executeGrass7使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grass7Utils.Grass7Utils
的用法示例。
在下文中一共展示了Grass7Utils.executeGrass7方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processAlgorithm
# 需要导入模块: from Grass7Utils import Grass7Utils [as 别名]
# 或者: from Grass7Utils.Grass7Utils import executeGrass7 [as 别名]
def processAlgorithm(self, progress):
commands = []
vector = self.getParameterValue(self.VECTOR)
elevation = self.getParameterValue(self.ELEVATION)
color = self.getParameterValue(self.COLOR)
region = \
str(self.getParameterValue(self.GRASS_REGION_EXTENT_PARAMETER))
regionCoords = region.split(',')
command = 'g.region '
command += 'n=' + str(regionCoords[3])
command += ' s=' + str(regionCoords[2])
command += ' e=' + str(regionCoords[1])
command += ' w=' + str(regionCoords[0])
cellsize = self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER)
if cellsize:
command += ' res=' + str(cellsize)
else:
command += ' res=' + str(self.getDefaultCellsize())
commands.append(command)
command = 'nviz7'
if vector:
layers = vector.split(';')
for layer in layers:
(cmd, newfilename) = self.exportVectorLayer(layer)
commands.append(cmd)
vector = vector.replace(layer, newfilename)
command += ' vector=' + vector.replace(';', ',')
if color:
layers = color.split(';')
for layer in layers:
(cmd, newfilename) = self.exportRasterLayer(layer)
commands.append(cmd)
color = color.replace(layer, newfilename)
command += ' color=' + color.replace(';', ',')
if elevation:
layers = elevation.split(';')
for layer in layers:
(cmd, newfilename) = self.exportRasterLayer(layer)
commands.append(cmd)
elevation = elevation.replace(layer, newfilename)
command += ' elevation=' + elevation.replace(';', ',')
if elevation is None and vector is None:
command += ' -q'
commands.append(command)
Grass7Utils.createTempMapset()
Grass7Utils.executeGrass7(commands, progress)
示例2: processAlgorithm
# 需要导入模块: from Grass7Utils import Grass7Utils [as 别名]
# 或者: from Grass7Utils.Grass7Utils import executeGrass7 [as 别名]
def processAlgorithm(self, progress):
commands = []
vector = self.getParameterValue(self.VECTOR)
elevation = self.getParameterValue(self.ELEVATION)
color = self.getParameterValue(self.COLOR)
region = str(self.getParameterValue(self.GRASS_REGION_EXTENT_PARAMETER))
regionCoords = region.split(",")
command = "g.region "
command += "n=" + str(regionCoords[3])
command += " s=" + str(regionCoords[2])
command += " e=" + str(regionCoords[1])
command += " w=" + str(regionCoords[0])
cellsize = self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER)
if cellsize:
command += " res=" + str(cellsize)
else:
command += " res=" + str(self.getDefaultCellsize())
commands.append(command)
command = "nviz7"
if vector:
layers = vector.split(";")
for layer in layers:
(cmd, newfilename) = self.exportVectorLayer(layer)
commands.append(cmd)
vector = vector.replace(layer, newfilename)
command += " vector=" + vector.replace(";", ",")
if color:
layers = color.split(";")
for layer in layers:
(cmd, newfilename) = self.exportRasterLayer(layer)
commands.append(cmd)
color = color.replace(layer, newfilename)
command += " color=" + color.replace(";", ",")
if elevation:
layers = elevation.split(";")
for layer in layers:
(cmd, newfilename) = self.exportRasterLayer(layer)
commands.append(cmd)
elevation = elevation.replace(layer, newfilename)
command += " elevation=" + elevation.replace(";", ",")
if elevation is None and vector is None:
command += " -q"
commands.append(command)
Grass7Utils.createTempMapset()
Grass7Utils.executeGrass7(commands, progress)
示例3: processAlgorithm
# 需要导入模块: from Grass7Utils import Grass7Utils [as 别名]
# 或者: from Grass7Utils.Grass7Utils import executeGrass7 [as 别名]
#.........这里部分代码省略.........
command += ' --overwrite'
commands.append(command)
# 3: Export resulting layers to a format that qgis can read
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.value
# Raster layer output: adjust region to layer before
# exporting
commands.append('g.region raster=' + out.name + uniqueSufix)
outputCommands.append('g.region raster=' + out.name
+ uniqueSufix)
if self.grass7Name == 'r.statistics':
# r.statistics saves its results in a non-qgis compatible
# way. Post-process them with r.mapcalc.
calcExpression = 'correctedoutput' + uniqueSufix
calcExpression += '[email protected]' + out.name + uniqueSufix
command = 'r.mapcalc expression="' + calcExpression + '"'
commands.append(command)
outputCommands.append(command)
command = 'r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW"'
command += ' input='
command += 'correctedoutput' + uniqueSufix
command += ' output="' + filename + '"'
elif self.grass7Name == 'r.composite':
command = 'r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW"'
command += ' input='
command += 'correctedoutput' + uniqueSufix
command += ' output="' + filename + '"'
else:
command = 'r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW"'
command += ' input='
if self.grass7Name == 'r.horizon':
command += out.name + uniqueSufix + '_0'
elif self.grass7Name == 'r.composite':
commands.append(command)
outputCommands.append(command)
elif self.grass7Name == 'r.statistics':
commands.append(command)
outputCommands.append(command)
else:
command += out.name + uniqueSufix
command += ' output="' + filename + '"'
commands.append(command)
outputCommands.append(command)
if isinstance(out, OutputVector):
filename = out.value
typeidx = self.getParameterValue(self.GRASS_OUTPUT_TYPE_PARAMETER)
outtype = ('auto' if typeidx
is None else self.OUTPUT_TYPES[typeidx])
if self.grass7Name == 'r.flow':
command = 'v.out.ogr type=line layer=0 -c -s -e input=' + out.name + uniqueSufix
elif self.grass7Name == 'v.voronoi':
if '-l' in command:
command = 'v.out.ogr type=line layer=0 -c -s -e input=' + out.name + uniqueSufix
else:
command = 'v.out.ogr -c -s -e input=' + out.name + uniqueSufix
command += ' type=' + outtype
elif self.grass7Name == 'v.sample':
command = 'v.out.ogr type=point -c -s -e input=' + out.name + uniqueSufix
else:
command = 'v.out.ogr -c -s -e input=' + out.name + uniqueSufix
command += ' type=' + outtype
command += ' output="' + os.path.dirname(out.value) + '"'
command += ' format=ESRI_Shapefile'
command += ' olayer=' + os.path.basename(out.value)[:-4]
commands.append(command)
outputCommands.append(command)
# 4: Run GRASS
loglines = []
loglines.append(self.tr('GRASS GIS 7 execution commands'))
for line in commands:
progress.setCommand(line)
loglines.append(line)
if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
Grass7Utils.executeGrass7(commands, progress, outputCommands)
for out in self.outputs:
if isinstance(out, OutputHTML):
with open(self.getOutputFromName("rawoutput").value) as f:
rawOutput = "".join(f.readlines())
with open(out.value, "w") as f:
f.write("<pre>%s</pre>" % rawOutput)
# If the session has been created outside of this algorithm, add
# the new GRASS GIS 7 layers to it otherwise finish the session
if existingSession:
Grass7Utils.addSessionLayers(self.exportedLayers)
else:
Grass7Utils.endGrass7Session()
示例4: processAlgorithm
# 需要导入模块: from Grass7Utils import Grass7Utils [as 别名]
# 或者: from Grass7Utils.Grass7Utils import executeGrass7 [as 别名]
#.........这里部分代码省略.........
command += ' ' + param.name + '=' + s
elif isinstance(param, ParameterBoolean):
if param.value:
command += ' ' + param.name
elif isinstance(param, ParameterSelection):
idx = int(param.value)
command += ' ' + param.name + '=' + str(param.options[idx])
elif isinstance(param, ParameterString):
command += ' ' + param.name + '="' + str(param.value) + '"'
else:
command += ' ' + param.name + '="' + str(param.value) + '"'
uniqueSufix = str(uuid.uuid4()).replace('-', '')
for out in self.outputs:
if isinstance(out, OutputFile):
if out.name == 'outputtext':
# The 'outputtext' file is generated by piping output
# from GRASS, is not an actual grass command
command += ' > ' + out.value
else:
command += ' ' + out.name + '="' + out.value + '"'
elif not isinstance(out, OutputHTML):
# Html files are not generated by GRASS, only by us to
# decorate GRASS output, so we skip them. An output name
# to make sure it is unique if the session uses this
# algorithm several times.
uniqueOutputName = out.name + uniqueSufix
command += ' ' + out.name + '=' + uniqueOutputName
# Add output file to exported layers, to indicate that
# they are present in GRASS
self.exportedLayers[out.value] = uniqueOutputName
command += ' --overwrite'
commands.append(command)
# 3: Export resulting layers to a format that qgis can read
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.value
# Raster layer output: adjust region to layer before
# exporting
commands.append('g.region raster=' + out.name + uniqueSufix)
outputCommands.append('g.region raster=' + out.name
+ uniqueSufix)
if self.grassName == 'r.composite':
command = 'r.out.tiff -t --verbose' # FIXME r.out.tiff deprecated, use r.out.gdal
command += ' input='
command += out.name + uniqueSufix
command += ' output="' + filename + '"'
commands.append(command)
outputCommands.append(command)
else:
command = 'r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW"'
command += ' input='
if self.grassName == 'r.horizon':
command += out.name + uniqueSufix + '_0'
else:
command += out.name + uniqueSufix
command += ' output="' + filename + '"'
commands.append(command)
outputCommands.append(command)
if isinstance(out, OutputVector):
filename = out.value
# FIXME: check if needed: -c Also export features without category (not labeled). Otherwise only features with category are exported.
command = 'v.out.ogr -s -e input=' + out.name + uniqueSufix
command += ' output="' + os.path.dirname(out.value) + '"'
command += ' format=ESRI_Shapefile'
command += ' olayer=' + os.path.basename(out.value)[:-4]
typeidx = \
self.getParameterValue(self.GRASS_OUTPUT_TYPE_PARAMETER)
outtype = ('auto' if typeidx
is None else self.OUTPUT_TYPES[typeidx])
command += ' type=' + outtype
commands.append(command)
outputCommands.append(command)
# 4: Run GRASS
loglines = []
loglines.append(self.tr('GRASS GIS 7 execution commands'))
for line in commands:
progress.setCommand(line)
loglines.append(line)
if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
self.consoleOutput = Grass7Utils.executeGrass7(commands, progress,
outputCommands)
self.postProcessResults()
# If the session has been created outside of this algorithm, add
# the new GRASS GIS 7 layers to it otherwise finish the session
if existingSession:
Grass7Utils.addSessionLayers(self.exportedLayers)
else:
Grass7Utils.endGrass7Session()
示例5: processAlgorithm
# 需要导入模块: from Grass7Utils import Grass7Utils [as 别名]
# 或者: from Grass7Utils.Grass7Utils import executeGrass7 [as 别名]
def processAlgorithm(self, progress):
if system.isWindows():
path = Grass7Utils.grassPath()
if path == '':
raise GeoAlgorithmExecutionException(
self.tr('GRASS GIS 7 folder is not configured. Please '
'configure it before running GRASS GIS 7 algorithms.'))
# Create brand new commands lists
self.commands = []
self.outputCommands = []
self.exportedLayers = {}
# If GRASS session has been created outside of this algorithm then
# get the list of layers loaded in GRASS otherwise start a new
# session
existingSession = Grass7Utils.sessionRunning
if existingSession:
self.exportedLayers = Grass7Utils.getSessionLayers()
else:
Grass7Utils.startGrass7Session()
# Handle ext functions for inputs/command/outputs
if self.module:
if hasattr(self.module, 'processInputs'):
func = getattr(self.module, 'processInputs')
func(self)
else:
self.processInputs()
if hasattr(self.module, 'processCommand'):
func = getattr(self.module, 'processCommand')
func(self)
else:
self.processCommand()
if hasattr(self.module, 'processOutputs'):
func = getattr(self.module, 'processOutputs')
func(self)
else:
self.processOutputs()
else:
self.processInputs()
self.processCommand()
self.processOutputs()
# Run GRASS
loglines = []
loglines.append(self.tr('GRASS GIS 7 execution commands'))
for line in self.commands:
progress.setCommand(line)
loglines.append(line)
if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
Grass7Utils.executeGrass7(self.commands, progress, self.outputCommands)
for out in self.outputs:
if isinstance(out, OutputHTML):
with open(self.getOutputFromName("rawoutput").value) as f:
rawOutput = "".join(f.readlines())
with open(out.value, "w") as f:
f.write("<pre>%s</pre>" % rawOutput)
# If the session has been created outside of this algorithm, add
# the new GRASS GIS 7 layers to it otherwise finish the session
if existingSession:
Grass7Utils.addSessionLayers(self.exportedLayers)
else:
Grass7Utils.endGrass7Session()