Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Geoprocessing
Scripts Using Python
The information contained in this document is the exclusive property of ESRI. This work is protected under United States
copyright law and the copyright laws of the given countries of origin and applicable international laws, treaties, and/or
conventions. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical,
including photocopying or recording, or by any information storage or retrieval system, except as expressly permitted in writing by
ESRI. All requests should be sent to Attention: Contracts Manager, ESRI, 380 New York Street, Redlands, CA 92373-8100, USA.
C O N T E
Introduction
Course objectives
Day 1 course content
Day 2 course content
Course materials
Additional materials and resources
ESRI Support Center
ESRI Developer Network
ArcGIS: a complete GIS
Logistics
Introductions
Exercise goals
Exercise 1: Install the class database (SBS)
Lesson 2 overview
What is geoprocessing?
Accessing geoprocessing tools
Inside ArcToolbox
Supported data types
System toolboxes
Tools with the same name
Tools and licensing
The geoprocessing framework
Environment settings
Class focus
Why write scripts?
Points of interest
The Python scripting language
Exercise 2 overview (SBS)
Exercise 2: The geoprocessing framework (SBS)
1-2
1-3
1-4
1-5
1-6
1-7
1-8
1-9
1-10
1-11
1-12
2-2
2-3
2-4
2-5
2-6
2-7
2-8
2-9
2-10
2-11
2-12
2-13
2-14
2-15
2-17
ii
Lesson 3 overview
Where to write code
PythonWin interface
IDLE interface
Comments
Variables in Python
Strings
Numbers and lists
Variable naming conventions
Line continuation
Built-in functions
Accessing modules
Statements
Decision making syntax
Looping syntax
Case sensitive rules
Common shortcut keys for PythonWin
Python resources
Exercise 3 overview (SBS)
Exercise 3: The basics of Python (SBS)
Lesson 4 overview
Common ArcObjects
Common ArcObjects
Interacting with ArcObjects
The Geoprocessor (GpDispatch) ArcObject
Creating the Geoprocessor
Syntax for properties and methods
Demonstration: Finding the scripting syntax
Toolbox aliases
The Select tool
The CreateFeatureClass tool
The (raster) Clip tool
The Buffer tool
The Union tool
Learning how to populate tool arguments
Contents
3-2
3-3
3-4
3-5
3-6
3-7
3-8
3-9
3-10
3-11
3-12
3-13
3-14
3-15
3-16
3-17
3-18
3-19
3-20
4-2
4-3
4-4
4-5
4-6
4-7
4-8
4-9
4-10
4-11
4-13
4-14
4-15
4-16
4-17
Contents
Lesson 5 overview
What you know
What you may not know
The Geoprocessor Programming Model
Finding the model
Object symbol
Property and method symbols
Object colors
Methods and properties on the Geoprocessor
Adding and removing toolboxes
Refreshing ArcCatalog
Checking if data exists
Overwriting the output
Getting help
Exercise 5 overview
Exercise 5A: Check if a folder exists (ILD)
Exercise 5B: Run Geoprocessor methods (SD)
Lesson 6 overview
Returning standard data
Returning objects
The describe objects
The describe method
The describe objects
Dataset properties
Feature class properties
Raster dataset properties
Describe object properties
Demonstration: Help for describe objects
Activity: Describing geodatabases
Activity: Describing coverages
4-18
4-19
5-2
5-3
5-4
5-5
5-6
5-7
5-8
5-9
5-10
5-11
5-12
5-13
5-14
5-15
5-16
6-2
6-3
6-4
6-5
6-6
6-7
6-8
6-9
6-10
6-11
6-12
6-13
6-14
iii
iv
Lesson 7 overview
The enumeration objects
The enumeration methods
The enumeration objects
The Enumeration object
List feature class example
List dataset example
Looping through a list of data
The Fields object
Activity: Complete the code
Exercise 7 overview
Exercise 7A: List feature classes (ILD)
Exercise 7B: List data (SD)
Lesson 8 overview
The cursor objects
The cursor methods
The cursor objects
The SearchCursor object
Search cursor example
The UpdateCursor object
Update cursor example
The InsertCursor object
Insert cursor example
The Geometry object
Geometry example
Data locks
Exercise 8 overview
Exercise 8A: Read values from fields (ILD)
Exercise 8B: Add and update a field (SD)
Contents
6-15
6-16
7-2
7-3
7-4
7-5
7-6
7-7
7-8
7-9
7-10
7-12
7-13
8-2
8-3
8-4
8-5
8-6
8-7
8-8
8-9
8-10
8-11
8-12
8-13
8-14
8-15
Contents
10
9-2
9-3
9-4
9-5
9-6
9-7
9-8
9-9
9-10
9-11
9-13
9-14
9-15
9-16
9-17
9-18
10-2
10-3
10-4
10-5
10-6
10-7
10-8
10-9
10-10
10-11
10-12
10-13
10-14
10-15
10-16
10-17