2024: Domino Containers - The Next Step. News from the Domino Container commu...
2008-03-04 - Geoprocessing with ArcGIS.pdf
1. 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
2. Reminder
Reminder
This week participate in the discussion forum
This week, participate in the discussion forum
P bl d
Practice problems are posted
Submit the “boxes” lab
Think about your proposed problems, data
needs and goals for your project
needs and goals for your project
3. Re-cap From Past Lectures
Re cap From Past Lectures
We’ve discussed modularization
We ve discussed modularization
– Subroutines
Functions
– Functions
– Object-orientation
All this leads to one thing:
Code Re-use
4. Code Re-Use
Code Re Use
The goal is to make life easier for us!
The goal is to make life easier for us!
I
Imports
– Single functions
– Modules
– Classes/objects
– Entire processing frameworks:
• PyGame, and ArcGIS’ Geoprocessing!
5. Objectives This Week
Objectives This Week
Learn about ArcGIS’ Geoprocessing objects
Learn 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
6. What is the ArcGIS Geoprocessing
Framework?
An “ArcObjects” component
R 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
7. Accessing the Geoprocessor
Object
How do we instantiate the Geoprocessor?
How do we instantiate the Geoprocessor?
import arcgisscripting
gp = 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:
on
gp.Toolbox = “Analysis”
Gp.clip(In,Clip,Out)
tho
p p( , p, )
Pyt
8. The Geoprocessor Object
The Geoprocessor Object
Uses environment settings to define the
Uses environment settings to define the
operating conditions, input/output, defaults
9. So Geoprocessing Opens Doors
So 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
13. Putting it all together
Putting 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”
14. Cataloguing and Listing Spatial Data
Cataloguing and Listing Spatial Data
One common and critical task:
One common and critical task:
– Batch Processing
W d thi ith G ’ Li t th d
We do this with Geoprocessor’s List methods
– Use for different data types
– List objects for iteration
15. Batch Processing
Batch 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
16. Enumerations
Enumerations
Some methods return
Some methods return
enumerations:
List (object) of values
– List (object) of values
without a known count
and of any type
y yp
Objects to be listed can
be restricted by data
be restricted by data
types and name
17. Parameters
Parameters
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”)
18. Type Filters
Type Filters
List methods by default list objects of all types
List 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
19. Iterating Through Enumerated
Features
Enumerated features are not Python lists
Enumerated 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
20. 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 top
objects, a es su e t e st e e e t s o top
– list.next() : returns the currently selected
y
value and increments the list index
24. Wrap-up
Wrap up
The Geoprocessing framework offers the
The Geoprocessing framework offers the
gateway to ArcGIS’ tools
It also provides functionality for sophisticated
h d
interactions 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
25. In Lab This Week
In Lab This Week
Explore Geoprocessing framework
Explore 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 refere
p p g p p p g_ _q _
nce_guide