本文整理汇总了Python中sextante.grass.GrassUtils.GrassUtils.getSessionLayers方法的典型用法代码示例。如果您正苦于以下问题:Python GrassUtils.getSessionLayers方法的具体用法?Python GrassUtils.getSessionLayers怎么用?Python GrassUtils.getSessionLayers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sextante.grass.GrassUtils.GrassUtils
的用法示例。
在下文中一共展示了GrassUtils.getSessionLayers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processAlgorithm
# 需要导入模块: from sextante.grass.GrassUtils import GrassUtils [as 别名]
# 或者: from sextante.grass.GrassUtils.GrassUtils import getSessionLayers [as 别名]
def processAlgorithm(self, progress):
if SextanteUtils.isWindows():
path = GrassUtils.grassPath()
if path == "":
raise GeoAlgorithmExecutionException("GRASS folder is not configured.\nPlease configure it before running GRASS 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 = GrassUtils.sessionRunning
if existingSession:
self.exportedLayers = GrassUtils.getSessionLayers()
else:
GrassUtils.startGrassSession()
#1: Export layer to grass mapset
for param in self.parameters:
if isinstance(param, ParameterRaster):
if param.value == 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 == 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 == None:
continue
layers = param.value.split(";")
if layers == 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 += " 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)
#2: set parameters and outputs
command = self.grassName
for param in self.parameters:
if param.value == 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):
continue
if isinstance(param, (ParameterRaster, ParameterVector)):
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])
s = s.replace(";",",")
command+=(" " + param.name + "=" + s);
#.........这里部分代码省略.........