Download - Python – Beyond the Basics
![Page 1: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/1.jpg)
Esri UC2013 . Technical Workshop .
Technical Workshop
2013 Esri International User ConferenceJuly 8–12, 2013 | San Diego, California
Python – Beyond the BasicsDavid Wynne, Ken Smith
![Page 2: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/2.jpg)
Esri UC2013 . Technical Workshop .
Agenda
Python – Beyond the Basics
Data structures &
functions
Script tools
Classes
Cursors
Geometry
![Page 3: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/3.jpg)
Esri UC2013 . Technical Workshop .
Data structures & functions
Python 201:
![Page 4: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/4.jpg)
Esri UC2013 . Technical Workshop .
Key Python data structures
Python – Beyond the Basics
![Page 5: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/5.jpg)
Esri UC2013 . Technical Workshop .
List comprehension
• Compact way of mapping a list into another
Python – Beyond the Basics
![Page 6: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/6.jpg)
Esri UC2013 . Technical Workshop .
Defining Functions
• Organize and re-use functionality
Python – Beyond the Basics
Define your function
Return a result
Call the function
![Page 7: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/7.jpg)
Esri UC2013 . Technical Workshop .
Data structures
Demo
![Page 8: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/8.jpg)
Esri UC2013 . Technical Workshop .
Script tools
![Page 9: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/9.jpg)
Esri UC2013 . Technical Workshop .
Quadrat Analysis tool
Demo
![Page 10: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/10.jpg)
Esri UC2013 . Technical Workshop .
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
![Page 11: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/11.jpg)
Esri UC2013 . Technical Workshop .
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
![Page 12: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/12.jpg)
Esri UC2013 . Technical Workshop .
Tip: Script Template
Python – Beyond the Basics
http://esriurl.com/4558http://esriurl.com/4558
![Page 13: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/13.jpg)
Esri UC2013 . Technical Workshop .
Part B: Jump start your analysis with a template
Quadrat Analysis tool
Demo
![Page 14: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/14.jpg)
Esri UC2013 . Technical Workshop .
arcpy classes
![Page 15: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/15.jpg)
Esri UC2013 . Technical Workshop .
arcpy classes
• Classes are used to create objects
• Frequently used for…- Tool parameters- Working with geometry
Python – Beyond the Basics
![Page 16: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/16.jpg)
Esri UC2013 . Technical Workshop .
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
![Page 17: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/17.jpg)
Esri UC2013 . Technical Workshop .
Using classes for parameters
• Extent
• SpatialReference
Python – Beyond the Basics
![Page 18: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/18.jpg)
Esri UC2013 . Technical Workshop .
Part C: •Extent class•Cursors•Chi-square function
Quadrat Analysis tool
Demo
![Page 19: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/19.jpg)
Esri UC2013 . Technical Workshop .
Recap
1. Fast developmentI. A script template gets you started
II. Easy access to tools and functions through arcpy
III. No UI development required
IV. Script tools provide default validation
Python – Beyond the Basics
![Page 20: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/20.jpg)
Esri UC2013 . Technical Workshop .
Recap…
2. Used a function to define / group useful functionality
3. Used open source libraries (numpy)
4. Easy to share and deploy- No ArcObjects or dlls to register
Python – Beyond the Basics
![Page 21: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/21.jpg)
Esri UC2013 . Technical Workshop .
Cursors
![Page 22: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/22.jpg)
Esri UC2013 . Technical Workshop .
Cursors
• Use cursors to access records and features
• Two varieties- ‘Classic’ cursors- ‘Data access’ cursors (new at 10.1)
Python – Beyond the Basics
![Page 23: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/23.jpg)
Esri UC2013 . Technical Workshop .
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
![Page 24: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/24.jpg)
Esri UC2013 . Technical Workshop .
With statements
• arcpy.da Cursors support with statements
Python – Beyond the Basics
![Page 25: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/25.jpg)
Esri UC2013 . Technical Workshop .
Cursor performance
• Use only those fields you need
• Use tokens- Get only what you need- Full geometry is
expensive
Python – Beyond the Basics
![Page 26: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/26.jpg)
Esri UC2013 . Technical Workshop .
arcpy.da cursors
Demo
![Page 27: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/27.jpg)
Esri UC2013 . Technical Workshop .
Geometry
![Page 28: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/28.jpg)
Esri UC2013 . Technical Workshop .
Geometry and cursors
• Can create geometry in different ways- Geometry objects
- List of coordinates
- Using other formats- JSON, WKT, WKB
Python – Beyond the Basics
![Page 29: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/29.jpg)
Esri UC2013 . Technical Workshop .
Geometry and cursors
• Can create geometry in different ways- Geometry objects
- List of coordinates
- Using other formats- JSON, WKT, WKB
Python – Beyond the Basics
![Page 30: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/30.jpg)
Esri UC2013 . Technical Workshop .
Working with geometry
• Relational: - Is a point within a polygon?
Python – Beyond the Basics
![Page 31: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/31.jpg)
Esri UC2013 . Technical Workshop .
Working with geometry
• Topological- What is the intersection of two
geometries?
Python – Beyond the Basics
![Page 32: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/32.jpg)
Esri UC2013 . Technical Workshop .
Working with geometry
• Others- What is the halfway point of a line?
- What is the geodesic area of a polygon?
Python – Beyond the Basics
![Page 33: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/33.jpg)
Esri UC2013 . Technical Workshop .
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
![Page 34: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/34.jpg)
Esri UC2013 . Technical Workshop .
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
Thank you…
Python – Beyond the Basics
![Page 35: Python – Beyond the Basics](https://reader034.vdocument.in/reader034/viewer/2022051402/568157ed550346895dc564ea/html5/thumbnails/35.jpg)
Esri UC2013 . Technical Workshop . Python – Beyond the Basics