Introduction to ArcPython Dan Mahr ‘11 10/28/2014 GEOL1320.

Slides:



Advertisements
Similar presentations
Geo GIS Practicuum Introduction to ArcGIS 8 Exercise 5 - ESRI Virtual Campus Chapters 1-2, ArcGIS Methods …
Advertisements

Concepts of Maintaining Your Data Simple Ways to Edit Your Data By Lorne Woods.
Environmental GIS Nicholas A. Procopio, Ph.D, GISP Some slides from Lyna Wiggins (Rutgers University)
Why python? Automate processes Batch programming Faster Open source Easy recognition of errors Good for data management What is python? Scripting programming.
Geographic Access to Primary Care Physicians in New Mexico Prepared for: Geog. 491(Problems) and Geog. 499 (Python programming) Fall Semester, 2014 Larry.
Introduction to Python. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
Introducing ArcGIS Desktop
Introduction to GIS and ArcGIS How a GIS works Introduction to ArcGIS The ArcGIS Interface.
GIS Topics and Applications
Python & ModelBuilder. Overview Python/ModelBuilder Concepts – The Geoprocessor – Checking some environment variables – Providing feedback from your model/script.
ModelBuilder In ArcGIS 9.x By Tim Weigel GEOG 407/607 April 3 rd, 2006.
Spatial Analysis, Geoprocessing,
ModelBuilder at ArcGIS 9.2 Lyna Wiggins Rutgers University May 2008.
ESRM 250/CFR 520 Winter 2010 Phil Hurvitz (with thanks to J. Lawler & P. Schiess) Introduction to GIS and ArcGIS 1 of 48.
Intro to ArcGIS Kate Dougherty, Geosciences & Maps Librarian Tutorial created for version 10.1 in February 2013.
Introduction to ArcGIS for Environmental Scientists Module 3 – GIS Analysis ArcGIS Toolbox.
Editing Basics (in ArcGIS 9.2) By Alma Vargas. Levels of Desktop ArcGIS Arc View Version that most clients will use The version that this session will.
Rebecca Boger Earth and Environmental Sciences Brooklyn College.
Habitat Analysis in ArcGIS Use of Spatial Analysis to characterize used resources Thomas Bonnot
Advance Model Builder Features. Advance Features Using Lists (also Batching) Iteration Feedback Model Only Tools Inline Variable Substitution Preconditions.
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
A First Program Using C#
Enterprise ETL & the Home Again
Technical Workshops | Esri International User Conference San Diego, California ArcMap: Tips and Tricks Miriam Schmidts Jorge Ruiz-Valdepena July 23 – 27,
Python & ModelBuilder. Continuing Education Python and ModelBuilder Overview Python/ModelBuilder Concepts –The Geoprocessor –Checking some environment.
Esri International User Conference | San Diego, CA Technical Workshops | Python – Getting Started Drew Flater, Ghislain Prince July 12 - July 14, 2011.
A Sample Print Web Service Utilizing ArcGIS Server and ArcObjects Cheryl Spencer, IndyGIS Marianne Cardwell, Woolpert.
Introduction to Spatial Analysis and Spatial Modeling
Introduction to Python John Reiser May 5 th, 2010.
Introduction to ArcPy. Topics What is ArcPy? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy.
Python: An Introduction
Introduction to ArcGIS. Goals Become familiar with ArcGIS ▫Locating and running the program ▫Introduction to the 3 ArcGIS interfaces ▫Experience with.
Python Map Automation: Introduction to arcpy.mapping / arcpy.mp
Internet and Distributed Representation of Agent Based Model by- Manish Sharma.
ArcGIS Network Analyst: Automating Workflows with Geoprocessing
Enabling High-Quality Printing in Web Applications
Programming for Geographical Information Analysis: Advanced Skills Lecture 1: Introduction Programming Arc Dr Andy Evans.
Introduction of Geoprocessing Topic 7a 4/10/2007.
Python, Toolboxes, Tools & Script Tools
Introduction to ArcGIS for Environmental Scientists Module 1 – Data Visualization Chapter 4 - Layouts.
Esri UC 2014 | Technical Workshop | Python Map Automation – Beyond the Basics of arcpy.mapping Jeff Barrette Jeff Moulds.
Introduction to ArcGIS for Environmental Scientists Module 3 – GIS Analysis Model Builder.
Introduction Presenter: James Zollweg, Ph.D. Associate Professor of Water Resources and GIS The College at Brockport NYS GIS Association – Python Training,
On the Take with Free and Low-Cost GIS Part 2: AccuGlobe 2007 FREE GIS Viewing Software Features & Functions Presented by: Phil Worrall, GIS Director Pinnacle.
Introduction of Geoprocessing Lecture 9. Geoprocessing  Geoprocessing is any GIS operation used to manipulate data. A typical geoprocessing operation.
Desktop Mapping: Building Map Books Jeff Barrette Michael Grossman.
DATA Spatial Data – where things are Non Spatial Data or Attribute Data – What things are Data in a computer database are managed and accessed through.
Introduction to Geographic Information Systems Fall 2013 (INF 385T-28620) Dr. David Arctur Research Fellow, Adjunct Faculty University of Texas at Austin.
Introduction of Geoprocessing Lecture 9 3/24/2008.
Python: Building Geoprocessing Tools David Wynne, Ghislain Prince.
Desktop Mapping: Building Map Books
PYTHON: AN INTRODUCTION
TE004 Smart Change Management with Sage CRM Component Manager
How to automatise the grid production - using model builder in ArcGIS
Environmental GIS Nicholas A. Procopio, Ph.D, GISP
Attribute Extraction.
String several geoprocessing processes
Spatial Data Processing
Workflows with ENVI and Esri Agriculture workflows for ICARDA
Programming for Geographical Information Analysis: Advanced Skills
Programming for Geographical Information Analysis: Advanced Skills
Python Map Automation – Beyond the Basics of arcpy.mapping
Building Map Books in ArcGIS
Web AppBuilder for ArcGIS
Python Map Automation – Beyond the Basics of arcpy.mapping
Building Map Books in ArcGIS
Network Analyst – Automating Workflows with Geoprocessing
Programming Arc.
Desktop Mapping: Building Map Books
Presentation transcript:

Introduction to ArcPython Dan Mahr ‘11 10/28/2014 GEOL1320

About me GEOL1320 fall 2009 GEOL1330 (remote sensing) spring 2010 Senior thesis with MODIS data, used GIS heavily Graduated 2011 Environmental consulting at The Cadmus Group (Waltham, MA)

About you How would you describe your knowledge of computer programming? 1.None 2.Basic 3.Intermediate 4.Expert Target audience

A confession: I can’t teach you Python in 60 minutes

Agenda What is ArcPython? Why learn arcpy? arcpy demo: Adding fields Showcase 1: Hydrologic analysis Showcase 2: Batch map creation Showcase 3: Service area model

What is ArcPython? Python is a programming language – Named after Monty Python – Focus on readability – Popular as scripting language ArcPython (arcpy) is the scripting package for ArcGIS – Functions and classes for performing ArcGIS tasks from the Python

Why bother learning ArcPy? Reason #1: Scale and speed – Same reasons we learned ModelBuilder! – ArcMap interface can be cumbersome and slow – Python allows for even larger-scale processing

ModelBuilder can be taken too far:

Why bother learning ArcPy? (cont.) Reason #2: Extendability – Leverage Python’s functionality in GIS workflows – Lots of other open-source GIS modules are in Python. Python is becoming a lingua franca of GIS

Showcase 1: Hydrologic Analysis What rivers are most likely to be impacted by runoff? Important in process of siting water quality monitoring stations Data available: – Hydrography (vector – line) – Land cover (raster) – Dams and culverts (vector – point) – Soil characteristics (vector – polygon) – Pesticide use (raster) – Etc.

Showcase 2: Batch map creation How to efficiently create lots of similar maps? If we knew we only had to do it once, it might be fastest to do “manually,” making maps one-by-one. Data driven pages has some functionality. But inevitably, someone will want the legend moved half an inch, or some other cosmetic change applied to every map. The arcpy mapping module is the most advanced solution to automating static map creation.

Showcase 3: Service Area Model How can we model (i.e. estimate) the extent of drinking water utility service areas? Relevant for water contaminant regulatory development and environmental justice Data available: – Rough location of water utility (mailing address, ZIP code) – Population served by water utility

Demo Task: Add field(s) to a shapefile As always with ArcGIS, there are multiple ways to get it done

Method 1: Attribute table

Method 2: ArcToolbox tool

Method 3: ModelBuilder

Method 4: Python Open the Python window in ArcMap by clicking the Python button in the Geoprocessing menu

Python basics Command line interface (CLI) runs Python and arcpy commands In some software, the graphical user interface is merely an abstraction layer over the CLI Python console in ArcMap is suitable for running small snippets of code and testing syntax; not suited towards running entire programs

Python basics (cont.) print is the command “Hello world!” is a string object that is output by the print command

Python basics (cont.) Python treats “+” as sum, which works as expected with integer ( int ) and floating point ( float ) objects. You can’t sum an int and a string ( str ), but you can concatenate two strings.

ArcPy commands Every tool accessible from the ArcToolbox and Search panes can be run from ArcPy. – In the example above, the Add Field tool from the Data Management toolbox is run.

ArcPy commands (cont.) How to find a command’s syntax? – Console code completion – Web documentation: m/en/help/main/10.2/ m/en/help/main/10.2/ – Export geoprocessing results to Python snippet – Export ModelBuilder to Python snippet From results window From Model Builder

ArcPy commands (cont.) FieldsToAdd is a Python list containing string objects that can be iterated through in a loop. In the for loop, the Field object becomes the pointer to each item in the FieldsToAdd list.

ArcPy commands (cont.) You can nest lists within lists. Any loops iterate through the outermost list with 3 elements.. You can reference elements in a list by their index. Field[0] returns the 1 st element (a field name string). Field[1] returns the 2 nd element (a field type string).

ArcPy commands (cont.) Python has great support for reading and writing external files, such as CSVs and XMLs. The reader object is the iterable being looped through, instead of the FieldsToAdd list.

ArcPy commands (cont.) The field names and field types from the CSV can be passed to the Add Field command. The startswith() function can prevent inadvertently adding the header fields. Right click to save this to a.py Python file.

Creating a Custom Toolbox Empty custom toolboxes can be made in the Catalog pane. Each toolbox can contain multiple tools Each tool references a Python script file with the.py extension.

Creating a Custom Toolbox (cont.)

1.Import arcpy module 2.Handle header fields more elegantly using next() 3.Use parameter values from our toolbox tool instead of hardcoded.csv file and table layer.

Creating a Custom Toolbox (cont.)

Questions?

Contact info and links Dan Mahr ’11 Resources ArcGIS 10.2 Help – GIS Q&A at StackExchange – gis.stackexchange.com gis.stackexchange.com Learn Python: – CodeCademy.com CodeCademy.com – DiveIntoPython.net DiveIntoPython.net