當前位置: 首頁>>代碼示例>>Python>>正文


Python GrassUtils.endGrassSession方法代碼示例

本文整理匯總了Python中sextante.grass.GrassUtils.GrassUtils.endGrassSession方法的典型用法代碼示例。如果您正苦於以下問題:Python GrassUtils.endGrassSession方法的具體用法?Python GrassUtils.endGrassSession怎麽用?Python GrassUtils.endGrassSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sextante.grass.GrassUtils.GrassUtils的用法示例。


在下文中一共展示了GrassUtils.endGrassSession方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: processAlgorithm

# 需要導入模塊: from sextante.grass.GrassUtils import GrassUtils [as 別名]
# 或者: from sextante.grass.GrassUtils.GrassUtils import endGrassSession [as 別名]

#.........這裏部分代碼省略.........
        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);
            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, ParameterSelection):
                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):
                command+=(" " + out.name + "=\"" + out.value + "\"");
            elif not isinstance(out, OutputHTML): #html files are not generated by grass, only by sextante to decorate grass output
                #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 rast=" + out.name + uniqueSufix)
                outputCommands.append("g.region rast=" + out.name + uniqueSufix)
                command = "r.out.gdal -c createopt=\"TFW=YES,COMPRESS=LZW\""
                command += " input="
                command += out.name + uniqueSufix
                command += " output=\"" + filename + "\""
                commands.append(command)
                outputCommands.append(command)

            if isinstance(out, OutputVector):
                filename = out.value
                command = "v.out.ogr -ce input=" + out.name + uniqueSufix
                command += " dsn=\"" + os.path.dirname(out.value) + "\""
                command += " format=ESRI_Shapefile"
                command += " olayer=" + os.path.basename(out.value)[:-4]
                command += " type=auto"
                commands.append(command)
                outputCommands.append(command)

        #4 Run GRASS
        loglines = []
        loglines.append("GRASS execution commands")
        for line in commands:
            progress.setCommand(line)
            loglines.append(line)
        if SextanteConfig.getSetting(GrassUtils.GRASS_LOG_COMMANDS):
            SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
        self.consoleOutput = GrassUtils.executeGrass(commands, progress, outputCommands);
        self.postProcessResults();
        # if the session has been created outside of this algorithm, add the new GRASS layers to it
        # otherwise finish the session
        if existingSession:
            GrassUtils.addSessionLayers(self.exportedLayers)
        else:
            GrassUtils.endGrassSession()
開發者ID:tomyun,項目名稱:Quantum-GIS,代碼行數:104,代碼來源:GrassAlgorithm.py


注:本文中的sextante.grass.GrassUtils.GrassUtils.endGrassSession方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。