Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language…...

Preview:

Citation preview

Python: An IntroductionCarl Eichenberger

February 24–25, 2016 | Washington, DC

FedGIS Conference

Agenda

• What is Python and why use it?• Python basics• The ArcPy Site Package• Geoprocessing script tools• Resources

What is Python?

• “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing…make it an ideal language for scripting…in many areas and on most platforms.”

• – python.org • Scripting language of ArcGIS

• Free, cross-platform, easy to learn, widely useful, great community

Why use Python and ArcGIS?

Automate repetitive tasks• Data management• Spatial analysis• Map automationCreate and share geoprocessing tools

Python Basics - Where do I write Python code?

• Python files have .py extension• IDE: PyScripter, PythonWin, IDLE, Notepad++• Python window in ArcGIS

Python Basics - How much Python do I need to know?

Building Blocks• Function: a defined piece of functionality that performs a specific task• Module: a Python file where functions live• Package: a collection of related modules

Python Standard Library / Built-ins• Types• Functions• Statements

DemoWriting Python code

Demo script

• Variables

Demo script

• Decision making (testing conditions)• Concatenating

Demo script

• Lists and Tuples

The ArcPy Site Package

Adds ArcGIS functionality to PythonAccess to geoprocessing toolsExamples of ArcPy functions, classes and modules• Functions: Describe and ListFeatureClasses• Classes: SpatialReference, Extent, and Geometry• Modules: Data Access and Mapping

Run geoprocessing tools

Python script tools

DemoWriting Python code

Resources

• resources.ArcGIS.com• GIS Stack Exchange, Stack Overflow• Python References• Python Scripting for ArcGIS by Zandbergen (Esri Press):

http://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=276&moduleID=0• Learning Python by Lutz: http://shop.oreilly.com/product/0636920028154.do

Python.org• Esri Training

Introduction to Geoprocessing Scripts using Python:http://training.esri.com/gateway/index.cfm?fa=catalog.courseDetail&CourseID=50131064_10.xPython for Everyone (free training):http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&courseid=2520

Resources

ArcPy topics covered in session

• Describing data: http://desktop.arcgis.com/en/desktop/latest/analyze/python/describing-data.htm

• Creating lists of data: http://desktop.arcgis.com/en/desktop/latest/analyze/python/listing-data.htm

• Creating script tools: http://desktop.arcgis.com/en/desktop/latest/analyze/creating-tools/adding-a-script-tool.htm

Recommended