Introduction To Geoprocessing Scripts Using Python: Student Edition
Introduction To Geoprocessing Scripts Using Python: Student Edition
Using Python®
Student Edition
Copyright © 2016 Esri
All rights reserved.
The information contained in this document is the exclusive property of Esri. This work is protected under United States
copyright law and other international copyright treaties and conventions. No part of this work may be reproduced or
transmitted in any form or by any means, electronic or mechanical, including photocopying and 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 and Legal Services Manager, Esri, 380 New York Street, Redlands, CA 92373-8100 USA.
EXPORT NOTICE: Use of these Materials is subject to U.S. export control laws and regulations including the U.S. Department
of Commerce Export Administration Regulations (EAR). Diversion of these Materials contrary to U.S. law is prohibited.
@esri.com, 3D Analyst, ACORN, Address Coder, ADF, AML, ArcAtlas, ArcCAD, ArcCatalog, ArcCOGO, ArcData, ArcDoc,
ArcEdit, ArcEditor, ArcEurope, ArcExplorer, ArcExpress, ArcGIS, ArcGlobe, ArcGrid, ArcIMS, ARC/INFO, ArcInfo, ArcInfo
Librarian, ArcLessons, ArcLocation, ArcLogistics, ArcMap, ArcNetwork, ArcNews, ArcObjects, ArcOpen, ArcPad, ArcPlot,
ArcPress, ArcPy, ArcReader, ArcScan, ArcScene, ArcSchool, ArcScripts, ArcSDE, ArcSdl, ArcSketch, ArcStorm, ArcSurvey,
ArcTIN, ArcToolbox, ArcTools, ArcUSA, ArcUser, ArcView, ArcVoyager, ArcWatch, ArcWeb, ArcWorld, ArcXML, Atlas GIS,
AtlasWare, Avenue, BAO, Business Analyst, Business Analyst Online, BusinessMAP, CityEngine, CommunityInfo, Database
Integrator, DBI Kit, EDN, Esri, Esri—Team GIS, Esri—The GIS Company, Esri—The GIS People, Esri—The GIS Software
Leader, FormEdit, GeoCollector, Geographic Design System, Geography Matters, Geography Network, GIS by Esri, GIS Day,
GIS for Everyone, GISData Server, JTX, MapIt, Maplex, MapObjects, MapStudio, ModelBuilder, MOLE, MPS—Atlas, PLTS,
Rent-a-Tech, SDE, SML, Sourcebook·America, SpatiaLABS, Spatial Database Engine, StreetMap, Tapestry, the ARC/INFO
logo, the ArcGIS logo, the ArcGIS Explorer logo, the ArcPad logo, the Esri globe logo, the Esri Press logo, the GIS Day logo,
the MapIt logo, The Geographic Advantage, The Geographic Approach, The World's Leading Desktop GIS, Water Writes,
www.arcgis.com, www.esri.com, www.geographynetwork.com, www.gis.com, www.gisday.com, and Your Personal
Geographic Information System are trademarks, service marks, or registered marks in the United States, the European
Community, or certain other jurisdictions. CityEngine is a registered trademark of Procedural AG and is distributed under
license by Esri.
Other companies and products or services mentioned herein may be trademarks, service marks or registered marks of their
respective mark owners.
Course introduction
Introduction
Course goals
Additional resources
Installing the course data
Icons used in this workbook
Understanding the ArcGIS Platform
2 Describing data
Lesson introduction
The Describe function
Generic Describe object properties
Feature class Describe properties
Raster Describe properties
Describing a feature class and raster
Fill-in-the-blank
Exercise 2: Work with the Describe object
Describe a feature class and a geodatabase
Describe a list of feature classes
Clip raster datasets with Describe object properties
Challenge: Describe dataset and coordinate system properties
Lesson review
i
3 Automating scripts with lists
Lesson introduction
The ArcPy List functions
Explore the ArcPy List functions
Working with List functions
Working with da.Walk
List data
Exercise 3: Automate scripts with the ArcPy List functions
List field properties
Buffer feature classes
Verify script results
Lesson review
ii
Exercise 5C: Work with the Insert cursor
Work with the da.InsertCursor
Error handling with Python
Error handling with the try-except statement
(Optional) Using the arcpy.da.Editor
Lesson review
7 Sharing scripts
Lesson introduction
Terms commonly used when sharing scripts
Scripting advantages in ArcMap
Making scripts dynamic
Debugging scripts in PyScripter
Creating and sharing a script tool
Advantages of attaching a script to a custom tool
Using the Add Script wizard
Running a script
Sharing a script
Plan out a project
Exercise 7: Share scripts through geoprocessing packages
Add pseudocode to the script
Write script code
Attach script to custom tool
Run script in ArcMap
iii
Share results as a geoprocessing package
Verify the geoprocessing package
Lesson review
Appendixes
Appendix A: Esri data license agreement
Appendix B: Answers to lesson review questions
Lesson 1: Running scripts in Python
Lesson 2: Describing data
Lesson 3: Automating scripts with lists
Lesson 4: Working with selections
Lesson 5: Working with cursors
Lesson 6: Working with geometry objects
Lesson 7: Sharing scripts
Lesson 8: Automating map production
iv