本文整理汇总了Python中Grass7Utils.Grass7Utils类的典型用法代码示例。如果您正苦于以下问题:Python Grass7Utils类的具体用法?Python Grass7Utils怎么用?Python Grass7Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Grass7Utils类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initializeSettings
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_FOLDER, 'GRASS7 folder',
Grass7Utils.grassPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_WIN_SHELL, 'Msys folder',
Grass7Utils.grassWinShell()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_LOG_COMMANDS,
'Log execution commands', False))
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_LOG_CONSOLE,
'Log console output', False))
示例2: processAlgorithm
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: help
def help(self):
localDoc = None
html = self.grass7Name + '.html'
if system.isWindows():
# For MS-Windows, use the configured GRASS7 path
localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html', html)
if os.path.exists(localPath):
localDoc = os.path.abspath(localPath)
elif system.isMac():
# For MacOSX official package
localPath = os.path.join('/Applications/GRASS-7.0.app/Contents/MacOS/docs/html', html)
if os.path.exists(localPath):
localDoc = os.path.abspath(localPath)
else:
# For GNU/Linux distributions
searchPaths = ['/usr/share/doc/grass-doc/html', '/opt/grass/docs/html',
'/usr/share/doc/grass/docs/html']
for path in searchPaths:
localPath = os.path.join(path, html)
if os.path.exists(localPath):
localDoc = os.path.abspath(localPath)
# Found the local documentation
if localDoc:
localDoc = QUrl.fromLocalFile(localDoc).toString()
return False, localDoc
# Return the URL if local doc is not found
return False, 'http://grass.osgeo.org/grass70/manuals/' + self.grass7Name + '.html'
示例4: processAlgorithm
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)
示例5: checkBeforeOpeningParametersDialog
def checkBeforeOpeningParametersDialog(self):
msg = Grass7Utils.checkGrass7IsInstalled()
if msg is not None:
html = '<p>This algorithm requires GRASS GIS 7 to be run. \
Unfortunately, it seems that GRASS GIS 7 is not installed in \
your system, or it is not correctly configured to be used \
from QGIS</p>'
html += '<p><a href="http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">Click here</a> to know more about how to install and configure GRASS GIS 7 to be used with QGIS</p>' # FIXME update URL or page
return html
示例6: getPostProcessingErrorMessage
def getPostProcessingErrorMessage(self, wrongLayers):
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
msg = Grass7Utils.checkGrass7IsInstalled(True)
html += '<p>This algorithm requires GRASS GIS 7 to be run. A test \
to check if GRASS GIS 7 is correctly installed and configured in \
your system has been performed, with the following \
result:</p><ul><i>'
if msg is None:
html += 'GRASS GIS 7 seems to be correctly installed and \
configured</i></li></ul>'
else:
html += msg + '</i></li></ul>'
html += '<p><a href= "http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">Click here</a> to know more about how to install and configure GRASS GIS 7 to be used with QGIS</p>'
return html
示例7: createAlgsList
def createAlgsList(self):
self.preloadedAlgs = []
folder = Grass7Utils.grassDescriptionPath()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
try:
alg = Grass7Algorithm(os.path.join(folder, descriptionFile))
if alg.name.strip() != '':
self.preloadedAlgs.append(alg)
else:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS GIS 7 algorithm: %s' % descriptionFile))
except Exception, e:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS GIS 7 algorithm: %s' % descriptionFile))
示例8: checkBeforeOpeningParametersDialog
def checkBeforeOpeningParametersDialog(self):
msg = Grass7Utils.checkGrass7IsInstalled()
if msg is not None:
return msg
示例9: processAlgorithm
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.'))
commands = []
self.exportedLayers = {}
outputCommands = []
# 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()
# 1: Export layer to grass mapset
for param in self.parameters:
if isinstance(param, ParameterRaster):
if param.value is None:
continue
value = param.value
# Check if the layer hasn't already been exported in, for
# example, previous GRASS calls in this session
if value in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(value, commands)
commands.append(self.exportRasterLayer(value))
if isinstance(param, ParameterVector):
if param.value is None:
continue
value = param.value
if value in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(value, commands)
commands.append(self.exportVectorLayer(value))
if isinstance(param, ParameterTable):
pass
if isinstance(param, ParameterMultipleInput):
if param.value is None:
continue
layers = param.value.split(';')
if layers is None or len(layers) == 0:
continue
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
for layer in layers:
if layer in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(layer, commands)
commands.append(self.exportRasterLayer(layer))
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
for layer in layers:
if layer in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(layer, commands)
commands.append(self.exportVectorLayer(layer))
self.setSessionProjectionFromProject(commands)
region = \
unicode(self.getParameterValue(self.GRASS_REGION_EXTENT_PARAMETER))
regionCoords = region.split(',')
command = 'g.region'
command += ' -a'
command += ' n=' + unicode(regionCoords[3])
command += ' s=' + unicode(regionCoords[2])
command += ' e=' + unicode(regionCoords[1])
command += ' w=' + unicode(regionCoords[0])
cellsize = self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER)
if cellsize:
command += ' res=' + unicode(cellsize)
else:
command += ' res=' + unicode(self.getDefaultCellsize())
alignToResolution = \
self.getParameterValue(self.GRASS_REGION_ALIGN_TO_RESOLUTION)
if alignToResolution:
command += ' -a'
commands.append(command)
# 2: Set parameters and outputs
command = self.grass7Name
for param in self.parameters:
if param.value is None or param.value == '':
continue
if param.name in [self.GRASS_REGION_CELLSIZE_PARAMETER, self.GRASS_REGION_EXTENT_PARAMETER, self.GRASS_MIN_AREA_PARAMETER, self.GRASS_SNAP_TOLERANCE_PARAMETER, self.GRASS_OUTPUT_TYPE_PARAMETER, self.GRASS_REGION_ALIGN_TO_RESOLUTION]:
continue
if isinstance(param, (ParameterRaster, ParameterVector)):
value = param.value
#.........这里部分代码省略.........
示例10: processAlgorithm
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.'))
commands = []
self.exportedLayers = {}
outputCommands = []
# 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()
# 1: Export layer to grass mapset
for param in self.parameters:
if isinstance(param, ParameterRaster):
if param.value is None:
continue
value = param.value
# Check if the layer hasn't already been exported in, for
# example, previous GRASS calls in this session
if value in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(value, commands)
commands.append(self.exportRasterLayer(value))
if isinstance(param, ParameterVector):
if param.value is None:
continue
value = param.value
if value in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(value, commands)
commands.append(self.exportVectorLayer(value))
if isinstance(param, ParameterTable):
pass
if isinstance(param, ParameterMultipleInput):
if param.value is None:
continue
layers = param.value.split(';')
if layers is None or len(layers) == 0:
continue
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
for layer in layers:
if layer in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(layer, commands)
commands.append(self.exportRasterLayer(layer))
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
for layer in layers:
if layer in self.exportedLayers.keys():
continue
else:
self.setSessionProjectionFromLayer(layer, commands)
commands.append(self.exportVectorLayer(layer))
self.setSessionProjectionFromProject(commands)
region = str(self.getParameterValue(self.GRASS_REGION_EXTENT_PARAMETER))
regionCoords = region.split(',')
command = 'g.region'
command += ' -a'
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())
alignToResolution = \
self.getParameterValue(self.GRASS_REGION_ALIGN_TO_RESOLUTION)
if alignToResolution:
command += ' -a'
commands.append(command)
# 2: Set parameters and outputs
command = self.grassName
for param in self.parameters:
if param.value is None or param.value == '':
continue
if param.name == self.GRASS_REGION_CELLSIZE_PARAMETER \
or param.name == self.GRASS_REGION_EXTENT_PARAMETER \
or param.name == self.GRASS_MIN_AREA_PARAMETER \
or param.name == self.GRASS_SNAP_TOLERANCE_PARAMETER \
or param.name == self.GRASS_OUTPUT_TYPE_PARAMETER \
#.........这里部分代码省略.........
示例11: checkBeforeOpeningParametersDialog
def checkBeforeOpeningParametersDialog(self):
return Grass7Utils.checkGrass7IsInstalled()
示例12: processAlgorithm
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()
示例13: canBeActivated
def canBeActivated(self):
return not bool(Grass7Utils.checkGrass7IsInstalled())