week 9 lecture: data and batch geoprocessing with...

25
Week 9 Lecture: Data and Batch Geoprocessing With Data and Batch Geoprocessing With ArcGIS Introduction to Programming for GIS & Remote Sensing GEO6938-4172 GEO4938-4166 GEO4938 4166

Upload: vuongkhanh

Post on 05-May-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

Week 9 Lecture:Data and Batch Geoprocessing With Data and Batch Geoprocessing With

ArcGISIntroduction to Programming for GIS & Remote Sensing

GEO6938-4172GEO4938-4166GEO4938 4166

ReminderReminder

This week participate in the discussion forumThis week, participate in the discussion forum

P bl dPractice problems are posted

Submit the “boxes” lab

Think about your proposed problems, data needs and goals for your projectneeds and goals for your project

Re-cap From Past LecturesRe cap From Past Lectures

We’ve discussed modularizationWe ve discussed modularization– Subroutines

Functions– Functions– Object-orientation

All this leads to one thing:Code Re-use

Code Re-UseCode Re Use

The goal is to make life easier for us!The goal is to make life easier for us!

IImports– Single functions– Modules– Classes/objects– Entire processing frameworks:

• PyGame, and ArcGIS’ Geoprocessing!

Objectives This WeekObjectives This Week

Learn about ArcGIS’ Geoprocessing objectsLearn about ArcGIS Geoprocessing objects

B ld M d l d h Building Models and integrating with scripts

Interface ArcGIS and other tools using Python as “glue”g

What is the ArcGIS GeoprocessingFramework?

An “ArcObjects” componentR ll j i l bj i h b– Really just a single object with many, many sub-components

Allows accessing geoproecessing tools as native methods

Accessing the GeoprocessorObject

How do we instantiate the Geoprocessor?How do we instantiate the Geoprocessor?import arcgisscriptinggp = arcgisscripting.create()gp g p g ()

How do we interact with the Geoprocessor?How do we interact with the Geoprocessor?gp.clip_analysis(In,Clip,Out) # alias for:

ongp.Toolbox = “Analysis”Gp.clip(In,Clip,Out) th

o

p p( , p, )

Pyt

The Geoprocessor ObjectThe Geoprocessor Object

Uses environment settings to define the Uses environment settings to define the operating conditions, input/output, defaults

So Geoprocessing Opens DoorsSo Geoprocessing Opens Doors

Besides access to ArcToolbox tools it gives Besides access to ArcToolbox tools it gives properties and methods to create and manipulate datasets directly!manipulate datasets directly!

S h d l h See the diagram again to explore that functionality…– Cataloguing– Describing– Listing– Editing

Class diagram on steroidsClass diagram on steroids…

The Geoprocessor Acts as Gateway…

To all of the power of ArcGIS and its tools:

Geoprocessor Programming Model

Reading the Programming ModelReading the Programming Model

Putting it all togetherPutting it all together…

Python gives you full functionality to Python gives you full functionality to programming environment

Operating/file system integration– Operating/file system integration– Fully extensible

All the logic you can stomach– All the logic you can stomach

Geoprocessing framework gives you all the l i A T lb l bili d tools in ArcToolbox plus ability to create and

edit data directly… == “Amazing Possibilities”

Cataloguing and Listing Spatial DataCataloguing and Listing Spatial Data

One common and critical task:One common and critical task:– Batch Processing

W d thi ith G ’ Li t th dWe do this with Geoprocessor’s List methods– Use for different data types– List objects for iteration

Batch ProcessingBatch Processing

Such a common programming Initialize Batch

Such a common programming structure

Sequence of operations

Read Data

– Sequence of operations– Iterated over list of items

Geoprocessing requires the inputs

Process Data

– Geoprocessing requires the inputs and outputs be organized

Output Results

EnumerationsEnumerations

Some methods return Some methods return enumerations:

List (object) of values – List (object) of values without a known count and of any typey yp

Objects to be listed can be restricted by data be restricted by data types and name

ParametersParameters

Wild cards: We can restrict the objects and datasets to be inserted into the list by Wild cards: We can restrict the objects and datasets to be inserted into the list by name using an asterisk:

myPolygonList = gp.ListFeatureClasses(“C*”)P l Li t Li tF t Cl (“* it *”)myPolygonList = gp.ListFeatureClasses(“*community*”)

Type filters: Restrict returns by certain type keywords:myPolygonList = gp.ListFeatureClasses(“C*”,”polygon”)

Input dataset values to restrict by items that are a part of a certain object:Input dataset values to restrict by items that are a part of a certain object:myPolygonList = gp.ListFields(table,“C*”,”Integer”)

Type FiltersType Filters

List methods by default list objects of all typesList methods by default list objects of all types

If f k d h l If you specify a keyword, you restrict the list returned to those types

Iterating Through Enumerated Features

Enumerated features are not Python listsEnumerated features are not Python lists

S h h h h l l So we iterate through them using while loops, not as for item in list: loops.

You test the condition before the loop, then p,the loop iterates until the test results in null/false

Iterating Through Enumerations (cont’d.)Iterating Through Enumerations (cont d.)

Two methods and no properties for Two methods and no properties for enumerations:

– list.reset() : Points to the top of the stack of objects, makes sure the first element is on topobjects, a es su e t e st e e e t s o top

– list.next() : returns the currently selected yvalue and increments the list index

Iterating Through Enumerations (cont’d.)Iterating Through Enumerations (cont d.)

Listing Tools and Their UsageListing Tools and Their Usage

onth

oPy

t

Your first batch “Union”Your first batch Union

Wrap-upWrap up

The Geoprocessing framework offers the The Geoprocessing framework offers the gateway to ArcGIS’ tools

It also provides functionality for sophisticated h dinteractions with data

– Batching is the most simple way to interact

Python’s native utility (e.g. string manipulation) y y ( g g p )and extensible modules (charts, statistics) can be married with ArcGIS

In Lab This WeekIn Lab This Week

Explore Geoprocessing frameworkExplore Geoprocessing framework– Build simple models/tools

E t t i t– Export to scripts– Create batch processes

Supplemental reading:– http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=What_is_geoprocessing?– http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=A_whirlwind_tour_of_geoprocessing– http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=Geoprocessing_tools– http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=Geoprocessing commands quick referep p g p p p g_ _q _

nce_guide