1 / 35

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. Agenda. Data structures & functions. Classes. Geometry. 1. 2. 3. 4. 5. Script tools. Cursors. Python 201:.

libba
Télécharger la présentation

Python – Beyond the Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2013 Esri International User Conference July 8–12, 2013 | San Diego, California Technical Workshop Python – Beyond the Basics David Wynne, Ken Smith

  2. 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 • Flexible • Ordered • Tuples • 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 • 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. 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. 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) 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 • pro.arcgis.com/analysis/python/ • ArcPy Café • arcpy.wordpress.com • Python at UC 2013 • esriurl.com/uc13python Python – Beyond the Basics

  34. 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

  35. Python – Beyond the Basics

More Related