330 likes | 339 Views
Presenter: James Zollweg, Ph.D. Associate Professor of Water Resources and GIS The College at Brockport. Introduction. NYS GIS Association – Python Training, Session 2 – July 17, 2012. 1. Python is an increasingly important part of ArcGIS mapping and geoprocessing
E N D
Presenter: James Zollweg, Ph.D. Associate Professor of Water Resources and GIS The College at Brockport Introduction NYS GIS Association – Python Training, Session 2 – July 17, 2012
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 Why a Python Seminar? NYS GIS Association – Python Training, Session 2 – July 17, 2012
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 Need to know NYS GIS Association – Python Training, Session 2 – July 17, 2012
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. Brief Review of Python Essentials 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
Study example scripts Example: ReplaceWithLayerFile.py So, how do you REALLY get started? 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
Rather than scouring scripts for ideas (a good way to learn “in general”), let’s make ArcGIS write code snippets for us! A VERY useful alternative 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
# 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.shp","100 Meters","FULL","ROUND","NONE","#") The snippet NYS GIS Association – Python Training, Session 2 – July 17, 2012
# 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.shp","100 Meters","FULL","ROUND","NONE","#") The snippet (with <cr>) NYS GIS Association – Python Training, Session 2 – July 17, 2012
(I’ll show how to use Model Builder later in the presentation) Model Builder -> Python 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
needs to be replaced with proper Python “for” loop Non-functional Python code generated 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
Members-only site for sharing scripts and snippets “Moderated” and organized Watch for details! The NYS GIS Association “App site” NYS GIS Association – Python Training, Session 2 – July 17, 2012
Congratulations for jousting with a useful, important and difficult topic! jzollweg@brockport.edu Thanks! NYS GIS Association – Python Training, Session 2 – July 17, 2012