![Page 1: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/1.jpg)
![Page 2: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/2.jpg)
Python: Beyond the BasicsMichael Rhoades
![Page 3: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/3.jpg)
Python: Beyond the BasicsSynopsis
This session is aimed at those with Python experience and who want to learn how to take Python further to solve analytical problems. This session will include accessing data with cursors, working with geometry, using third-party libraries, and creating Python-based geoprocessingtools.
Python – Beyond the Basics
![Page 4: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/4.jpg)
What are the basics?
![Page 5: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/5.jpg)
Python: Beyond the BasicsAgenda
Data structures &
functionsCreating your
own toolsCursors
Data Access
Features & Geometry
3rd party libraries
The road ahead
Python – Beyond the Basics
![Page 6: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/6.jpg)
Esri UC 2014 | Technical Workshop |
Functions & data structures
Python – Beyond the Basics
![Page 7: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/7.jpg)
• Organize and re-use functionality
• https://docs.python.org/2/tutorial/controlflow.html#defining-functions
Defining Functions
Define your function
Return a resultCall the function
Python – Beyond the Basics
![Page 8: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/8.jpg)
Key Python data structures
• Lists- Flexible - Ordered
• Tuples- Immutable - Ordered
• Dictionary- Key/value pairs
• https://docs.python.org/2/tutorial/datastructures.html
Python – Beyond the Basics
![Page 9: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/9.jpg)
Esri UC 2014 | Technical Workshop |
Data structures
Demo
![Page 10: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/10.jpg)
Esri UC 2014 | Technical Workshop |
Cursors and Data Access (arcpy.da)
Python – Beyond the Basics
![Page 11: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/11.jpg)
Cursors
• Use cursors to access records and features
• Two varieties- ‘Data access’ cursors (10.1 onwards)- ‘Classic’ cursors
SearchCursor Read-only
UpdateCursor Update or delete rows
InsertCursor Insert rows
Python – Beyond the Basics
![Page 12: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/12.jpg)
Cursor mechanics
• Data access cursors use lists and tuples- Values are accessed by index
Python – Beyond the Basics
![Page 13: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/13.jpg)
Cursor performance
• Use only those fields you need
• Use tokens- Get only what you need- Full geometry is expensive
Python – Beyond the Basics
![Page 14: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/14.jpg)
Data Access Editor
• Roll back and Save your data
Python – Beyond the Basics
![Page 15: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/15.jpg)
Data Access Walk
• Walk through your data- Stored in predefined list
Python – Beyond the Basics
![Page 16: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/16.jpg)
Esri UC 2014 | Technical Workshop |
Demo
Cursors and Data Access
![Page 17: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/17.jpg)
Esri UC 2014 | Technical Workshop |
Geometry
Python – Beyond the Basics
![Page 18: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/18.jpg)
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 19: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/19.jpg)
Working with geometry
• Relational: - Is a point within a polygon?
Python – Beyond the Basics
![Page 20: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/20.jpg)
Working with geometry
• Topological- What is the intersection of two geometries?
Python – Beyond the Basics
![Page 21: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/21.jpg)
Working with geometry
• More:- What is the halfway point of a line?
- What is the geodesic area of a polygon?
Python – Beyond the Basics
![Page 22: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/22.jpg)
Esri UC 2014 | Technical Workshop |
Demo
Geometry
![Page 23: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/23.jpg)
Esri UC 2014 | Technical Workshop |
Creating geoprocessing tools
Python – Beyond the Basics
![Page 24: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/24.jpg)
Geoprocessing Framework and Python
• Tools can be called from Python• Python code can be wrapped into a tool
• Custom Python tools …- Looks and behaves like system tools- Provides default validation- Have no UI programming
Python – Beyond the Basics
![Page 25: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/25.jpg)
• A tool does 3 types of work
1. Defines its parameters
2. Validates its parameters
3. Executes code that performs the actual work
Creating geoprocessing toolsScript tools Python toolboxes
Python – Beyond the Basics
![Page 26: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/26.jpg)
Getting and setting parameters
• Parameters are received using either:- arcpy.GetParameterAsText : value is a string- arcpy.GetParameter : appropriate object type
• You can also send a parameter value back for a derived output/value with:- arcpy.SetParameterAsText- arcpy.SetParameter
![Page 27: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/27.jpg)
Messages in a script tool
• Add custom messages into the tool’s messages- AddError- AddMessage- AddWarning- AddIDMessage
• Note: Error messages do not raise an Exception• For unhandled exceptions, all exception messages are added to the tool
messages
![Page 28: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/28.jpg)
Esri UC 2014 | Technical Workshop |
Script tools
Demo
Python – Beyond the Basics
![Page 29: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/29.jpg)
3rd party libraries
• Python has a rich set of 3rd party libraries- https://pypi.python.org/pypi
• We include several to support tools and other functionality
• NumPy- A powerful array object - Sophisticated analysis capabilities- arcpy support conversion to and from rasters, feature classes, and tables
Python – Beyond the Basics
![Page 30: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/30.jpg)
Esri UC 2014 | Technical Workshop |
Demo
3rd party library - Request
![Page 31: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/31.jpg)
Esri UC 2014 | Technical Workshop |
Road ahead
Python – Beyond the Basics
![Page 32: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/32.jpg)
• arcpy is supported in ArcGIS Pro- arcpy.mapping has evolved- A subset of geoprocessing tools will disappear
• ArcGIS Pro will use Python 3.4- Your Python code may be okay as is- Definitely possible to write code that will work in both Python 2 and 3
Road ahead
Python – Beyond the Basics
![Page 33: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/33.jpg)
• Resources:- Python’s 2to3 utility- Analyze Tools For Pro- python3porting.com
Planning ahead
Python – Beyond the Basics
![Page 34: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/34.jpg)
![Page 35: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/35.jpg)
![Page 36: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/36.jpg)
![Page 37: Python: Beyond the Basics - Esri€¦ · Python: Beyond the Basics. Synopsis. This session is aimed at those with Python experience and who want to learn how to take Python further](https://reader030.vdocument.in/reader030/viewer/2022013010/5f02ff227e708231d407071d/html5/thumbnails/37.jpg)