introduction to gis programming by jun liang department of geography unc-ch

26
Introduction to GIS Introduction to GIS Programming Programming By Jun Liang By Jun Liang Department of Geography Department of Geography UNC-CH UNC-CH

Post on 22-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Introduction to GIS Introduction to GIS Programming Programming

By Jun LiangBy Jun Liang

Department of GeographyDepartment of Geography

UNC-CHUNC-CH

AudiencesAudiences

Who might be interested in this topic?Who might be interested in this topic?

- Bored with repeating GIS operationsBored with repeating GIS operations

- Do not like the default look (GUI) of Do not like the default look (GUI) of Commercial softwareCommercial software

- Has difficulties in standardizing map outputHas difficulties in standardizing map output

- Functions you need are not available in your Functions you need are not available in your GIS softwareGIS software

Preparing for GIS ProgrammingPreparing 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?Can I do it?

Question Question –– can I write programs for GIS can I write programs for GIS applications? Is it difficult to do?applications? Is it difficult to do?

Answer Answer –– It depends on what do you want to It depends on what do you want to do. do.

At most time, you can, At most time, you can, at least I believe. at least I believe. It is just another language It is just another language –– easier than most foreign easier than most foreign languages.languages.

Where to start?Where to start?

It may already exist somewhere.It may already exist somewhere.

If you are looking a tool, a function,If you are looking a tool, a function,

wwhich you could not find in your GIS software, hich you could not find in your GIS software, you may google it first, or try to find it in a you may google it first, or try to find it in a community website, such as community website, such as arcscripts.esri.com.arcscripts.esri.com.

Write your own.Write your own.

GIS Interests are GrowingGIS Interests are Growing

Mapping/GeoVisualization

Spatial Information Management

Spatial AnalysisSpatial Modeling

GovernmentEducation/Research Business/Industry

Application ExamplesApplication Examples

- Public HealthPublic Health- Environmental StudiesEnvironmental Studies- Urban PlanningUrban Planning- Water Resources ManagementWater Resources Management- Crime Mapping / Crime Pattern AnalysisCrime Mapping / Crime Pattern Analysis- Store Location OptimizationStore Location Optimization- Internet Mapping / RoutingInternet Mapping / Routing- Transportation/LogisticsTransportation/Logistics

Complexity of GIS ApplicationsComplexity of GIS Applications

Simple

Complex

Data manage, Mapping

Query, Measurement

Basic spatial analysis

Advanced spatial analysis

Integrated expert systems

GIS programming could be used for different level applications.

Data VolumeData Volume

Before proceed to write programs for your GIS Before proceed to write programs for your GIS applications, you may already have finished applications, you may already have finished data collection. The size of your data data collection. The size of your data collection will affect the way you are going to collection will affect the way you are going to code.code.

- Large volume: multiple Gig bitesLarge volume: multiple Gig bites

- Intermediate volume: 100Mb – 1 GigIntermediate volume: 100Mb – 1 Gig

- Small volume: ~100MbSmall volume: ~100Mb

Geo-ComputationGeo-Computation

Complexity/CPUComplexity/CPU time is another factor you time is another factor you need to estimate, before you design your need to estimate, before you design your program.program.

- Several days +Several days +- Within a dayWithin a day - Several hours- Several hours

- Within an hour- Within an hour Issues you may need to Issues you may need to

decide: decide: hardware andhardware and algorithm algorithm

Data Flow – Program Flow ChartData Flow – Program Flow ChartCensusTracts

(Input Features) Clip (Analysis Tools/Proximity Toolset)

CensusTractsClip (in

TransformScratch.mdb)StreamBuffer(Clip Features)

The flow chart will explain:

Spatial functions/tools you need to use

Parameters for functions

Output definitions

Program Logic Structure/Work flow

Implementation StructuresImplementation Structures

There are different ways youThere are different ways youcan implement your GIScan implement your GISprograms, based on:programs, based on:- GIS software you usedGIS software you used- Availability of tools/functionsAvailability of tools/functions- The nature of your application (share with The nature of your application (share with

other people? Going to used by other other people? Going to used by other people who have limited GIS experiences? people who have limited GIS experiences? Etc.)Etc.)

First Approach – Write your own code First Approach – Write your own code without help from existing GIS softwarewithout help from existing GIS software

Your Research Project/Application/Model

GIS functions – neededby your model

Do not need spatial visualization; data management; hard to be shared or reused by other people; one time application.

Programming Programming –– on your own on your own

Some examples of the first approaches Some examples of the first approaches ––

(1)(1) Downloading data routinely from a website Downloading data routinely from a website and use them for your model.and use them for your model.

(2)(2) Analyzing the average transportation cost Analyzing the average transportation cost from one point to a set of points. (location from one point to a set of points. (location optimization.)optimization.)

You can use any programming languages you You can use any programming languages you are familare familiiar with, such as Java, C, etc.ar with, such as Java, C, etc.

Approach 2 – Customizing existing Approach 2 – Customizing existing GIS softwareGIS software

- Using macro - Using macro language to language to customize customize existing GIS existing GIS software: GUI software: GUI focused focused application. application.

Providing service Providing service to general to general public.public.

Approach 3 – Creating new functions Approach 3 – Creating new functions using GIS macro/scriptsusing GIS macro/scripts

GIS Software

Your GIS ProgramCoding spatial models, or other non-spatial models with GIS macro languages, scripts.

Approach 4 – Loosely and tightly Approach 4 – Loosely and tightly coupled integration coupled integration

GIS Software – Provides basic commands,

macros, etc.

External ProgramModule

Loosely-Couple Architecture for integrating your Models (scripts, codes, etc) with GIS software

Data

Tightly Coupled ApplicationsTightly Coupled Applications

GIS Software – Provides basic commands,

macros, etc.

Pre-compiled Programs

Data

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 ProgrammingArcGIS 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.

GUI-Interface Geo-processing

Changing A Layer’s NameChanging A Layer’s Name

MxDocument

Map

*

Layer

*

Application

FeatureLayer

RasterLayerr

LineElement

ElementGeometry

Color Symbol GraphicElement FrameElement

TextElement MarkerElement PolygonElement

To make graphics on a map, you create objects out of the coclass under GraphicElement.

Class Diagram to help Class Diagram to help programmingprogramming

Using Python for GeoprocessingUsing Python for GeoprocessingESRI 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.

Scripting FunctionalitiesScripting Functionalities

An simple python exampleAn simple python example

import arcgisscripting gp = arcgisscripting.create() gp .Workspace = “c :\\Data\\Canada .mdb” gp.Buffer(”Streams”, “NoBuildZone”, 100) gp.Erase(”LandUse”, “NoBuildone”,

“BuildZone”)