Masthead

Assignment: Calling ArcGIS from Python

1. Researching Watersheds

Create a python script that finds the area of the watershed behind the of the North Fork Dam. You'll need a shapefile for the North Fork dam and a DEM of Oregon.

Create a Python module (file) with a function that returns the watershed boundary based on a DEM and an inintial point. The parameters to the function should be a file path to a DEM, a file path to a shapefile with one or more points for the dam(s), and a file path to the final polygon shapefile. The function will need to:

Below is some code to get you started. Notice that in one function call you'll specify an input and output file path while in another, ArcGIS returns a raster "object" which you then save to a file. You'll need to change the file paths and you'll have to determine the format and values for the "clipping bounds".

import arcpy # connect to ArcGIS

arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput=True # Allows us to run the script repeatedly without deleting the intermdiate files

# Clip the DEM to the area of interest
arcpy.Clip_management(OriginalFolder+"dem30",ClippingBounds,ProcessingFolder+"DemClip3.img","#","#","NONE")

print("Clipped DEM")

# Create a DEM with sinks filled
FilledRaster=arcpy.sa.Fill(ProcessingFolder+"DemClip3.img")
FilledRaster.save(ProcessingFolder+"FilledRaster.img")

Note: Remember to place the overall script in a "try/except" block and fully document both files.

Turn-in:

  1. A finished Python script with documentation and exception handling
  2. A Python module with a funtion to compute the watershed and full documentation

Extra credit:

Print out other statistics about the watershed, run the script for a number of dams in Oregon.

© Copyright 2018 HSU - All rights reserved.