Introduction Presenter: James Zollweg, Ph.D. Associate Professor of Water Resources and GIS The College at Brockport NYS GIS Association – Python Training, Session 2 – July 17, 2012
Why a Python Seminar? 1. Python is an increasingly important part of ArcGIS mapping and geoprocessing 2. Python 'scripting' is a powerful tool for modeling and process automation 3. Build a greater sense of community among GIS professionals in NYS via shared professional development NYS GIS Association – Python Training, Session 2 – July 17, 2012
Need to know 1. The elements of Python – a general purpose programming language 2. ArcPy - provides Python access for all geoprocessing tools, as well as a wide variety of useful functions and classes for working with and interrogating GIS data. 3. Proficiency in ArcGIS mapping and geoprocessing NYS GIS Association – Python Training, Session 2 – July 17, 2012
Brief Review of Python Essentials Python is a free, cross-platform, open-source programming language that is both powerful and easy to learn. It is widely used and supported. To learn more about Python, visit python.org. NYS GIS Association – Python Training, Session 2 – July 17, 2012
Values and variables NYS GIS Association – Python Training, Session 2 – July 17, 2012
Definite repetition NYS GIS Association – Python Training, Session 2 – July 17, 2012
Indefinite Repetition NYS GIS Association – Python Training, Session 2 – July 17, 2012
Lists NYS GIS Association – Python Training, Session 2 – July 17, 2012
List Layers NYS GIS Association – Python Training, Session 2 – July 17, 2012
List Attributes NYS GIS Association – Python Training, Session 2 – July 17, 2012
So, how do you REALLY get started? Study example scripts Example: ReplaceWithLayerFile.py NYS GIS Association – Python Training, Session 2 – July 17, 2012
Title NYS GIS Association – Python Training, Session 2 – July 17, 2012
Exception Handling NYS GIS Association – Python Training, Session 2 – July 17, 2012
Exception Handling NYS GIS Association – Python Training, Session 2 – July 17, 2012
Title NYS GIS Association – Python Training, Session 2 – July 17, 2012
A VERY useful alternative Rather than scouring scripts for ideas (a good way to learn “in general”), let’s make ArcGIS write code snippets for us! NYS GIS Association – Python Training, Session 2 – July 17, 2012
A familiar geoprocessing operation... NYS GIS Association – Python Training, Session 2 – July 17, 2012
Access the “results” of GP operation NYS GIS Association – Python Training, Session 2 – July 17, 2012
Copy operation to a Python “snippet” NYS GIS Association – Python Training, Session 2 – July 17, 2012
The snippet # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script# The following inputs are layers or table views: "recreation"arcpy.Buffer_analysis("recreation","C:/tem p/tests/buff3.shp","100 Meters","FULL","ROUND","NONE","#") NYS GIS Association – Python Training, Session 2 – July 17, 2012
The snippet (with <cr>) # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script # The following inputs are layers or table views: "recreation“ arcpy.Buffer_analysis("recreation","C:/temp/tests/buff3.s hp","100 Meters","FULL","ROUND","NONE","#") NYS GIS Association – Python Training, Session 2 – July 17, 2012
Model Builder -> Python (I’ll show how to use Model Builder later in the presentation) NYS GIS Association – Python Training, Session 2 – July 17, 2012
Export to Python script NYS GIS Association – Python Training, Session 2 – July 17, 2012
The result NYS GIS Association – Python Training, Session 2 – July 17, 2012
Excellent source of information NYS GIS Association – Python Training, Session 2 – July 17, 2012
Another example NYS GIS Association – Python Training, Session 2 – July 17, 2012
Output NYS GIS Association – Python Training, Session 2 – July 17, 2012
Beware – repetition does not functionally export fro MB NYS GIS Association – Python Training, Session 2 – July 17, 2012
Non-functional Python code generated needs to be replaced with proper Python “for” loop NYS GIS Association – Python Training, Session 2 – July 17, 2012
Replace with proper Python repetition NYS GIS Association – Python Training, Session 2 – July 17, 2012
Shameless plug for the NYS GIS Association NYS GIS Association – Python Training, Session 2 – July 17, 2012
The NYS GIS Association “App site” Members-only site for sharing scripts and snippets “Moderated” and organized Watch for details! NYS GIS Association – Python Training, Session 2 – July 17, 2012
Thanks! Congratulations for jousting with a useful, important and difficult topic! jzollweg@brockport.edu NYS GIS Association – Python Training, Session 2 – July 17, 2012