Download presentation
Presentation is loading. Please wait.
1
Python – Beyond the Basics
2013 Esri International User Conference July 8–12, 2013 | San Diego, California Technical Workshop Python – Beyond the Basics David Wynne, Ken Smith
2
Data structures & functions
Agenda Data structures & functions Classes Geometry 1 2 3 4 5 Script tools Cursors Python – Beyond the Basics
3
Python 201: Data structures & functions Python – Beyond the Basics
4
Key Python data structures
Lists Tuples Flexible Immutable Ordered Dictionary Key/value pairs Python – Beyond the Basics
5
List comprehension Compact way of mapping a list into another
Python – Beyond the Basics
6
Defining Functions Organize and re-use functionality
Define your function Return a result Call the function Python – Beyond the Basics
7
Demo Data structures Python – Beyond the Basics
8
Script tools Python – Beyond the Basics
9
Demo Quadrat Analysis tool Python – Beyond the Basics
10
Geoprocessing Framework and Python
Tools can be called from Python Python code can be turned into a tool A script tool… Looks and behaves like any system tool Provides default validation Has no UI programming Python – Beyond the Basics
11
Script tools Tools have parameters Script tools support messages
Use GetParameterAsText (or GetParameter) to get inputs Script tools support messages arcpy.AddMessage arcpy.AddWarning arcpy.AddError Python – Beyond the Basics
12
Tip: Script Template http://esriurl.com/4558
Python – Beyond the Basics
13
Quadrat Analysis tool Part B: Jump start your analysis with a template
Demo Quadrat Analysis tool Part B: Jump start your analysis with a template Python – Beyond the Basics
14
arcpy classes Python – Beyond the Basics
15
arcpy classes Classes are used to create objects Frequently used for…
Tool parameters Working with geometry Python – Beyond the Basics
16
arcpy Classes Most tool parameters are easily defined with a string or number Some are not: Spatial reference Field map Classes can be used to define these parameters Python – Beyond the Basics
17
Using classes for parameters
Extent SpatialReference Python – Beyond the Basics
18
Quadrat Analysis tool Part C: Extent class Cursors Chi-square function
Demo Quadrat Analysis tool Part C: Extent class Cursors Chi-square function Python – Beyond the Basics
19
Recap Fast development A script template gets you started
Easy access to tools and functions through arcpy No UI development required Script tools provide default validation Python – Beyond the Basics
20
Recap… Used a function to define / group useful functionality
Used open source libraries (numpy) Easy to share and deploy No ArcObjects or dlls to register Python – Beyond the Basics
21
Cursors Python – Beyond the Basics
22
Cursors Use cursors to access records and features Two varieties
‘Classic’ cursors ‘Data access’ cursors (new at 10.1) SearchCursor Read-only UpdateCursor Update or delete rows InsertCursor Insert rows Python – Beyond the Basics
23
Cursor mechanics Data access cursors use lists and tuples
Values are accessed by index Classic cursors use row objects Values are accessed by setValue/getValue Python – Beyond the Basics
24
With statements arcpy.da Cursors support with statements
Python – Beyond the Basics
25
Cursor performance Use only those fields you need Use tokens
Get only what you need Full geometry is expensive Python – Beyond the Basics
26
Demo arcpy.da cursors Python – Beyond the Basics
27
Geometry Python – Beyond the Basics
28
Geometry and cursors Can create geometry in different ways
Geometry objects List of coordinates Using other formats JSON, WKT, WKB Python – Beyond the Basics
29
Geometry and cursors Can create geometry in different ways
Geometry objects List of coordinates Using other formats JSON, WKT, WKB Python – Beyond the Basics
30
Working with geometry Relational: Is a point within a polygon?
Python – Beyond the Basics
31
Working with geometry Topological
What is the intersection of two geometries? Python – Beyond the Basics
32
Working with geometry Others What is the halfway point of a line?
What is the geodesic area of a polygon? Python – Beyond the Basics
33
Resources Python resource center ArcPy Café Python at UC 2013
pro.arcgis.com/analysis/python/ ArcPy Café arcpy.wordpress.com Python at UC 2013 esriurl.com/uc13python Python – Beyond the Basics
34
First Offering ID (Tues.): 1210 Second Offering ID (Wed.): 1311
Thank you… Please fill out the session evaluation First Offering ID (Tues.): 1210 Second Offering ID (Wed.): 1311 Online – Paper – pick up and put in drop box Python – Beyond the Basics
35
Python – Beyond the Basics
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.