进入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>")

用Python作GIS之五:从示例入手—example函数的更多相关文章

  1. 用Python作GIS之二:STARS开发环境配置

    STARS的一般使用可以通过REGAL网页快速学习http://regionalanalysislab.org/?n=STARS再次不做详细介绍这里关注的主题是对STARS源代码分析即为使用Pytho ...

  2. 用Python作GIS之一:介入STARS

    STARS的全称是Space-Time Analysis of Regional Systems,直译过来就是区域系统时空分析软件.这是针对区域多时相数据的分析包,源代码公开.该软件将最近几年发展起来 ...

  3. 用Python作GIS之四:Tkinter基本界面的搭建

    Python下的主窗口可以定义如下:def start(self):        #self.project = Project("temp")        #self.pro ...

  4. 用Python作GIS之三:入口程序 - stargui.py

    """gui start file for Space-Time Analysis of Regional Systems#STARS的图形用户界面入口(高级用户可以直接 ...

  5. C++开发python windows版本的扩展模块示例

    C++开发python windows版本的扩展模块示例 测试环境介绍和准备 测试环境: 操作系统:windows10 Python版本:3.7.0 VS版本:vs2015社区版(免费) 相关工具下载 ...

  6. python中hashlib模块用法示例

    python中hashlib模块用法示例 我们以前介绍过一篇Python加密的文章:Python 加密的实例详解.今天我们看看python中hashlib模块用法示例,具体如下. hashlib ha ...

  7. Python自定义线程类简单示例

    Python自定义线程类简单示例 这篇文章主要介绍了Python自定义线程类,结合简单实例形式分析Python线程的定义与调用相关操作技巧,需要的朋友可以参考下.具体如下: 一. 代码     # - ...

  8. python golang中grpc 使用示例代码详解

    python 1.使用前准备,安装这三个库 pip install grpcio pip install protobuf pip install grpcio_tools 2.建立一个proto文件 ...

  9. Python Socket 编程——聊天室示例程序

    上一篇 我们学习了简单的 Python TCP Socket 编程,通过分别写服务端和客户端的代码了解基本的 Python Socket 编程模型.本文再通过一个例子来加强一下对 Socket 编程的 ...

随机推荐

  1. Appium移动自动化测试(四)--先跑起来再说(第一个测试用例-手机YY)

    说明 本文将详细说明如何使用Appnium完成:打开手机YY欢迎页面->按住屏幕向左滑动4次->按下"立即体验"按钮->按下"直播"按钮,的整 ...

  2. 网站图片优化-解码JPEG

    首先,老大拿了两个网站工具的分析跟我说,让我分析一下我们网站的图片有没有什么方法优化. [网站分析工具]webpage test: http://www.webpagetest.org/谷歌pages ...

  3. 基本的git命令

    git是一个分布式管理工具,可以用于代码的管理和维护(每次更新,修改,增加,删除); -->初始化一个仓库 git init 然后会在你所在的文件夹中添加一个隐藏文件.git(这是一个本地数据库 ...

  4. The BKS System for the Philco-2000 学习笔记

    最近因为学业需要阅读这一篇论文......一把鼻涕一把泪地翻了一边以求更好地理解,谁让我英语渣呢....有很多地方翻译得感觉还是有问题或者不流畅,还请大家多多指教. The BKS System fo ...

  5. python --那些你应该知道的知识点

    1.python函数参数(含星号参数)http://blog.useasp.net/archive/2014/06/23/the-python-function-or-method-parameter ...

  6. 学习记录 java 值类型和引用类型的知识

    1. Java中值类型和引用类型的不同? [定义] 引用类型表示你操作的数据是同一个,也就是说当你传一个参数给另一个方法时,你在另一个方法中改变这个变量的值, 那么调用这个方法是传入的变量的值也将改变 ...

  7. 洛谷P1113 杂物

    P1113 杂务 251通过 441提交 题目提供者该用户不存在 标签图论递推 难度普及/提高- 提交该题 讨论 题解 记录 最新讨论 为什么会只有10分? 题目描述 John的农场在给奶牛挤奶前有很 ...

  8. phonegap ios默认启动页

    phonegap创建的项目默认的启动界面是phonegap的图标,想去掉这个图标,有两个方法,第一就是将resourece下面的splash文件下面的图片改成自己想要的启动页面,名字要相同,替换掉它默 ...

  9. iOS地址编码解析

    - (void)viewDidLoad { [super viewDidLoad]; // 创建地址解析器 self.geocoder = [[CLGeocoder alloc] init]; } - ...

  10. 【Hibernate 6】常用的hql语句以及N+1问题

    HQL:Hibernate Query Language,是Hibernate框架中的查询语言,十分接近于SQL语言!以下介绍一些常用的Hql语句: 一.测试类 Classes类: <span ...