16
Python: An Introduction Carl Eichenberger February 24–25, 2016 | Washington, DC FedGIS Conference

Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Python: An IntroductionCarl Eichenberger

February 24–25, 2016 | Washington, DC

FedGIS Conference

Page 2: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Agenda

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

Page 3: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

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

Page 4: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Why use Python and ArcGIS?

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

Page 5: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Python Basics - Where do I write Python code?

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

Page 6: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

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

Page 7: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

DemoWriting Python code

Page 8: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Demo script

• Variables

Page 9: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Demo script

• Decision making (testing conditions)• Concatenating

Page 10: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Demo script

• Lists and Tuples

Page 11: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

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

Page 12: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Run geoprocessing tools

Page 13: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

Python script tools

Page 14: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

DemoWriting Python code

Page 15: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

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

Page 16: Python: An Introduction · What is Python? • “Python is an easy to learn, powerful language… (with) high level data structures and a simple but effective approach to object

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