Lecture 21 Using Arc Toolbox Tools in Python

Lecture 21: Using Arc. Toolbox Tools in Python Jeffery S. Horsburgh CEE 5190/6190 Geographic Information Systems for Civil Engineers Spring 2017

Reminders • Lab today is semester project work • Lab next week HW 8 • Lab Monday 24 th – Final project presentations • Grad Students: Initial draft of final report due Wednesday. Use the template and look at the rubric.

Objectives • Create a Python script that automates a complex geoprocessing task not easily accomplished with core GIS software functionality ◦ Introduction to the Python programming language ◦ Write and execute computer code to automate repetitive tasks • Become proficient in the use of GIS tools to conduct spatial analyses

Demo: Run Arc. Toolbox Tools in Python • Run the tool in Arc. Toolbox • Open the Geoprocessing “Results” window • Expand the entry for the tool you just ran and select “Copy As Python Snippet” • Paste the code into Idle or another text editor to construct your script • Save your script as a “. py” file

Executing Script • Open the Arc. Map Python Console from the toolbar • Right click in the console and select “Load” • Select your “. py” script file from disk • Hit Enter to execute

Python Programming Challenge • Using the DEM and outlet shapefile provided, write a Python script that extracts streams and delineates the watershed above the outlet 1. 2. 3. 4. 5. 6. 7. Fill pits Calculate flow direction raster Calculate flow accumulation raster Extract stream network raster (Threshold = 500) Snap outlet point to outlet raster Delineate watershed raster Convert watershed raster to polygon • Run the tools from Arc. Toolbox and copy the code • Generate one “. py” script file and save • Load and execute in Arc. Map Python window

Result Watershed

Hints • If you run the tools from Arc. Toolbox and create the datasets in your geodatabase, you will have to delete them before you try to run your script or you will get errors • Check to make sure the geoprocessing Environment setting “Processing Extent” and “Snap Raster” are set to process the extent of the NED grid Upload your resulting Python Script (your “. py” file) to the Participation Assignment in Canvas for credit before you leave class.
- Slides: 8