惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
L
LangChain Blog
Jina AI
Jina AI
博客园 - 叶小钗
B
Blog RSS Feed
Recent Announcements
Recent Announcements
H
Help Net Security
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
B
Blog
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客

博客园 - columbus2

用Python作GIS之四:Tkinter基本界面的搭建 用Python作GIS之三:入口程序 - stargui.py 用Python作GIS之二:STARS开发环境配置 用Python作GIS之一:介入STARS OpenBlock:针对EveryBlock.com源码的开源拓展项目 EveryBlock源代码 空间数据可视化 GeoDjango教程[3] GeoDjango教程[2] GeoDjango教程[1] 地理信息技术在现场项目的应用浅析 ESRI and SAP 防卫力量与公共安全:SAP与地理信息的集成 VRML之desk [地图投影之C实现]原数据 [地图投影之C实现]主程序 [地图投影之C实现]PARAMETE.H [地图投影之C实现]BASIC_FU.C 关于地图投影的C程序的一些说明
用Python作GIS之五:从示例入手—example函数
columbus2 · 2015-02-23 · via 博客园 - columbus2

进入STARS后,最简单的学习方法就是演示示例数据。对于源码的分析也可以从这里入手。

      

以下为出发菜单项“Example Project”的函数example:
def example(self):
        """canned loading of data files and matrices for debugging"""
        self.project = SProject("current",self.master,self)
        topDir = options.getSTARSHOME()
        self.project.directory = os.path.join(topDir,"data")
        projectFile = os.path.join(self.project.directory,"csiss.prj")
        t=self.project.ReadProjectFile(projectFile)
        if hasattr(self.project,"coords"):
            self.project.scaleCoords()
        else:
            self.report("no coords in project")
        #self.master.configure(cursor=options.DEFAULTCURSOR)
        #self.Editor.configure(cursor='crosshair')
        self.projectSummary()
        self.enableMenus()

加粗标注的几行代码可作进一步详细了解:

(1)SProject:
代码如下所示
class SProject(Project):
    """Subclass to compose STARS project inside a GUI
   """
    def __init__(self,name,master,app):
        """Constructor

        name (string): name of project
        master (Tk): application top level window
        app (App): App instance
        """
        Project.__init__(self,name)
        self.master = master
        self.app = app
        self.fnt=("Times",10)
        self.screenHeight = self.app.winfo_screenheight()
        self.screenWidth = self.app.winfo_screenwidth()
        if self.screenWidth > 1280:
            self.screenWidth = 1280 # prevent spread across 2-extended displays
        s = str(self.screenWidth) + " " + str(self.screenHeight)
        self.screenDim = s

其中调用了父类Project,打开star.py文件,找到Project类,对其进行分析:
class Project:
    """Stars project.
    
    Example Usage:
        >>> from stars import Project
        >>> s=Project("s")
        >>> s.ReadData("csiss")
        >>> income=s.getVariable("pcincome")
        >>> region=s.getVariable("bea")
        >>> w=spRegionMatrix(region)
        >>> mi=Moran(income,w)
        >>> print(mi.mi[70])
        0.38918107312
    """
    def __init__(self,name):
        self.name = name
        self.dataBase = Database()
        self.getVariable = self.dataBase.getVariable
        self.getMatrix = self.dataBase.getMatrix
        self.addMatrix = self.dataBase.addMatrix
        self.getMatrixNames = self.dataBase.getMatrixNames
        self.getVariableNames = self.dataBase.getVariableNames
        self.getTSVariableNames = self.dataBase.getTSVariableNames
        self.getCSVariableNames = self.dataBase.getCSVariableNames
        self.getCSTSVariableNames = self.dataBase.getCSTSVariableNames

(2)ReadProjectFile:
代码如下所示
def ReadProjectFile(self,fileName):
        #assumes extension is passed into fileName

        #check for file existence
        if os.path.exists(fileName):
            self.initialize()
            config = ConfigParser.ConfigParser()
            config.read(fileName)
            projectDir = os.path.dirname(fileName)
            #print config.sections()
            for section in config.sections():
                options = config.options(section)
                for option in options:
                    value = config.get(section,option)
            #        print section,option,value
                    sec=self.options[section]
                    opt=sec[option]
                    opt.append(value)
                    sec[option]=opt
                    self.options[section]=sec
           # self.summarizeOptions()


            # read data files
            dataFiles = self.options["data"]["files"]
            for dataFile in dataFiles:
           #     print dataFile
                dfile = os.path.join(projectDir,dataFile)
           #     print dfile
                self.ReadData(dfile)
            #print "data files"

            # read any gal matricies
            try:
                galFiles = self.options["weight"]["gal"][0].split()
                print galFiles
                for galFile in galFiles:
           #         print galFile
                    gfile = os.path.join(projectDir,galFile)
                    self.ReadGalMatrix(gfile)
            #print "gal"
            except:
                print "No Weights Matrices"

            # read any gis boundary files
            self.listGISNames = []
            gisFiles = self.options["gis"]["gis"]
            for gisFile in gisFiles:
                fileName = gisFile+".gis"
                self.listGISNames.append(fileName)
                fileName = os.path.join(projectDir,fileName)
                self.ReadGisFile(fileName)

                fileName = os.path.join(projectDir,gisFile+".cnt")
                if os.path.exists(fileName): 
                    self.readCentroids(fileName)
                else:
                    self.__calcCentroids()
            self.gisResolution = self.options["graphics"]["screen"]
        else:
            print "Error: Cannot read project file: %s"%fileName

该段代码可以帮助解析STARS工程文件project的大致结构,打开系统自带示例的工程文件csiss.prj:
[data]
files: csiss
[weight]
gal: states48

[gis]
gis: us48

[graphics]
screen: 1280 1201

可以发现该文件分为四段,前三段分别对应有数据文件、权重文件、GIS文件的连接,最后一段为显示参数。
·数据文件存储统计数据信息,又分为两个文件:csiss.dht存储数据索引信息,csiss.dat存储数据主体信息,其中注释CS为空间序列数据,TS为时间序列数据,CSTS即为时空序列数据。
·权重文件存储空间权重信息,后缀名为gal。此文件第一行为空间实体数目,从第二行开始每两行构成固定格式,形如:[第一行]实体序号 权重关联实体个数[第二行]权重关联实体序号列表,如此循环至最后一个实体。参见states48.gal文件。
·GIS文件(后缀名为gis)存储空间实体的地图数据,结构形如:[数据头]空间实体编号 该实体内多边形编号 该多边形节点数[数据体]X坐标(换行)Y坐标。参见us48.gis文件。

(3)projectSummary:
代码如下所示
def projectSummary(self):
        self.report(self.project.catalogue())

在guimaker.py中找到report函数:
def report(self,message):
        """enters messages into main application window. use for
        entering results, commands called by gui, etc."""
        self.Editor.insert(END,message)
        t=len(message)
        self.Editor.yview_scroll(t,UNITS)
        self.Editor.insert(END,"\n>")