260 likes | 377 Views
Introduction to GIS Programming . By Jun Liang Department of Geography UNC-CH. Audiences. Who might be interested in this topic? Bored with repeating GIS operations Do not like the default look (GUI) of Commercial software Has difficulties in standardizing map output
E N D
Introduction to GIS Programming By Jun Liang Department of Geography UNC-CH
Audiences Who might be interested in this topic? • Bored with repeating GIS operations • Do not like the default look (GUI) of Commercial software • Has difficulties in standardizing map output • Functions you need are not available in your GIS software
Preparing for GIS Programming • GIS software operations: know what are you doing • Spatial Data Models: • Understand what are dealing with • Basic Spatial Analytical Functions: Have a GIS brain • Knowledge on Programming: Integer? Binary? Loops? Logical operators?
Can I do it? Question – can I write programs for GIS applications? Is it difficult to do? Answer – It depends on what do you want to do. At most time, you can, at least I believe. It is just another language – easier than most foreign languages.
Where to start? • It may already exist somewhere. If you are looking a tool, a function, which you could not find in your GIS software, you may google it first, or try to find it in a community website, such as arcscripts.esri.com. • Write your own.
GIS Interests are Growing Spatial Analysis Spatial Modeling Spatial Information Management Mapping/GeoVisualization Education/Research Business/Industry Government
Application Examples • Public Health • Environmental Studies • Urban Planning • Water Resources Management • Crime Mapping / Crime Pattern Analysis • Store Location Optimization • Internet Mapping / Routing • Transportation/Logistics
Complexity of GIS Applications Data manage, Mapping Query, Measurement Basic spatial analysis Advanced spatial analysis Integrated expert systems Simple Complex GIS programming could be used for different level applications.
Data Volume Before proceed to write programs for your GIS applications, you may already have finished data collection. The size of your data collection will affect the way you are going to code. • Large volume: multiple Gig bites • Intermediate volume: 100Mb – 1 Gig • Small volume: ~100Mb
Geo-Computation Complexity/CPU time is another factor you need to estimate, before you design your program. • Several days + • Within a day - Several hours - Within an hour Issues you may need to decide: hardware and algorithm
CensusTracts (Input Features) Clip (Analysis Tools/Proximity Toolset) CensusTractsClip (in TransformScratch.mdb) StreamBuffer (Clip Features) Data Flow – Program Flow Chart The flow chart will explain: Spatial functions/tools you need to use Parameters for functions Output definitions Program Logic Structure/Work flow
Implementation Structures There are different ways you can implement your GIS programs, based on: • GIS software you used • Availability of tools/functions • The nature of your application (share with other people? Going to used by other people who have limited GIS experiences? Etc.)
First Approach – Write your own code without help from existing GIS software Your Research Project/Application/Model GIS functions – needed by your model Do not need spatial visualization; data management; hard to be shared or reused by other people; one time application.
Programming – on your own Some examples of the first approaches – • Downloading data routinely from a website and use them for your model. • Analyzing the average transportation cost from one point to a set of points. (location optimization.) You can use any programming languages you are familiar with, such as Java, C, etc.
Approach 2 – Customizing existing GIS software - Using macro language to customize existing GIS software: GUI focused application. Providing service to general public.
Approach 3 – Creating new functions using GIS macro/scripts GIS Software Coding spatial models, or other non-spatial models with GIS macro languages, scripts. Your GIS Program
Approach 4 – Loosely and tightly coupled integration Data GIS Software – Provides basic commands, macros, etc. External Program Module Loosely-Couple Architecture for integrating your Models (scripts, codes, etc) with GIS software
Tightly Coupled Applications Data GIS Software – Provides basic commands, macros, etc. Pre-compiled Programs GIS software can talk to some pre-compiled programs during execution – the integration usually looks seamless. It is just like that you can edit Excel object in your Word document.
ArcGIS Programming • The most recent release of ESRI’s ArcGIS® suite incorporates both Visual Basic and Python scripts. However, Python is well-suited to geoprocessing and much of the code in ArcGIS 9 that performs these types of functions is written in Python. Geo-processing GUI-Interface
* * MxDocument FeatureLayer RasterLayerr Application Layer Map Changing A Layer’s Name
PolygonElement MarkerElement TextElement LineElement Geometry Element Color Symbol GraphicElement FrameElement To make graphics on a map, you create objects out of the coclass under GraphicElement.
Using Python for Geoprocessing ESRI chose Python as the support language for geoprocessing because: • Python is easy to learn because of its clean syntax and simple, clear concepts. • Python supports object-oriented programming in an easy-to-understand manner. • Documenting Python is easier because it has readable code. • Complicated data structures are easy to work with in Python. • Python is simple to integrate with C++ and Fortran. • Python can be seamlessly integrated with Java. • Python is free from the Web and has a widespread community.
An simple python example • import arcgisscripting • gp = arcgisscripting.create() • gp .Workspace = “c :\\Data\\Canada .mdb” • gp.Buffer(”Streams”, “NoBuildZone”, 100) • gp.Erase(”LandUse”, “NoBuildone”, “BuildZone”)