350 likes | 512 Views
2013 Esri International User Conference July 8–12, 2013 | San Diego, California. Technical Workshop. Python – Beyond the Basics. David Wynne, Ken Smith. Agenda. Data structures & functions. Classes. Geometry. 1. 2. 3. 4. 5. Script tools. Cursors. Python 201:.
E N D
2013 Esri International User Conference July 8–12, 2013 | San Diego, California Technical Workshop Python – Beyond the Basics David Wynne, Ken Smith
Agenda Data structures & functions Classes Geometry 1 2 3 4 5 Script tools Cursors Python – Beyond the Basics
Python 201: Data structures & functions Python – Beyond the Basics
Key Python data structures • Lists • Flexible • Ordered • Tuples • Immutable • Ordered • Dictionary • Key/value pairs Python – Beyond the Basics
List comprehension • Compact way of mapping a list into another Python – Beyond the Basics
Defining Functions • Organize and re-use functionality Define your function Return a result Call the function Python – Beyond the Basics
Demo Data structures Python – Beyond the Basics
Script tools Python – Beyond the Basics
Demo Quadrat Analysis tool Python – Beyond the Basics
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
Script tools • Tools have parameters • Use GetParameterAsText (or GetParameter) to get inputs • Script tools support messages • arcpy.AddMessage • arcpy.AddWarning • arcpy.AddError Python – Beyond the Basics
Tip: Script Template http://esriurl.com/4558 Python – Beyond the Basics
Demo Quadrat Analysis tool Part B: Jump start your analysis with a template Python – Beyond the Basics
arcpy classes Python – Beyond the Basics
arcpy classes • Classes are used to create objects • Frequently used for… • Tool parameters • Working with geometry Python – Beyond the Basics
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
Using classes for parameters • Extent • SpatialReference Python – Beyond the Basics
Demo Quadrat Analysis tool Part C: Extent class Cursors Chi-square function Python – Beyond the Basics
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
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
Cursors Python – Beyond the Basics
Cursors • Use cursors to access records and features • Two varieties • ‘Classic’ cursors • ‘Data access’ cursors (new at 10.1) Python – Beyond the Basics
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
With statements • arcpy.da Cursors support with statements Python – Beyond the Basics
Cursor performance • Use only those fields you need • Use tokens • Get only what you need • Full geometry is expensive Python – Beyond the Basics
Demo arcpy.da cursors Python – Beyond the Basics
Geometry Python – Beyond the Basics
Geometry and cursors • Can create geometry in different ways • Geometry objects • List of coordinates • Using other formats • JSON, WKT, WKB Python – Beyond the Basics
Geometry and cursors • Can create geometry in different ways • Geometry objects • List of coordinates • Using other formats • JSON, WKT, WKB Python – Beyond the Basics
Working with geometry • Relational: • Is a point within a polygon? Python – Beyond the Basics
Working with geometry • Topological • What is the intersection of two geometries? Python – Beyond the Basics
Working with geometry • Others • What is the halfway point of a line? • What is the geodesic area of a polygon? Python – Beyond the Basics
Resources • Python resource center • pro.arcgis.com/analysis/python/ • ArcPy Café • arcpy.wordpress.com • Python at UC 2013 • esriurl.com/uc13python Python – Beyond the Basics
Thank you… Please fill out the session evaluation First Offering ID (Tues.): 1210 Second Offering ID (Wed.): 1311 Online – www.esri.com/ucsessionsurveys Paper – pick up and put in drop box Python – Beyond the Basics