Delineating Watershed for Federally Protected Plant

Determining the Intersection of
Development Project Footprint with
Protected Plant Watersheds
Chelsey Stephenson, GEOG 562, Spring 2017, Oregon
State University
Small whorled pogonia, Federally Threatened
Goal:
-Determine intersection between development project and
protected plant population watersheds
Inputs:
-Natural Heritage Program (NHP) occurrence data set
-DEM
-development project footprint shapefile
Outputs:
-NHP occurrence subset shapefiles
-watershed polygon shapefiles for each species
-buffered development project shapefile
-watershed/project intersection shapefiles for each
species
Harperella, Federally Endangered
Swamp pink, Federally Threatened
Study Area and Data:
1) A digital elevation model
(DEM) was acquired
from USGS and clipped
to an approximately
12x15km area
2) A “mock” NHP data set
3) Hypothetical pipeline
centerline
Code flow-chart
Watershed polygon shapefiles for
each species
Virginia DEM
NHP dataset
3
2
1
arcpy.Select_analysis
function
Pipeline centerline
shapefile
create list of watershed
shapefiles
watershed
delineation function
loop
arcpy.Buffer_analysis
function
watersheds_List
4
Shapefiles of recent
occurrences for each species of
interest
create list of species
shapefiles
species_List
arcpy.Intersect_analysis
function loop
Buffered pipeline
shapefile
Polygon shapefiles of intersection
between watershed polygons and
pipeline buffer
Step 1: Subset data
Input: NHP dataset
Output: species specific subset with only occurrence since 2012 for:
1. harperella
2. small whorled pogonia
3. swamp pink
Code snippet:
#use select analysis function to subset harperella occurrences from 2012 onward
harp_only = path + "/harp_nhp.shp"
where_clause = '"CMN_name" = \'harperella\' AND "YEAR" > 2011'
arcpy.Select_analysis(nhp_data, harp_only, where_clause)
print "harp select complete"
Step 2: delineate watershed
Inputs: list of shapefiles from step 1, clipped DEM
Outputs: polygon watershed shapefiles for each species
Code snippet:
for species in spp_List:
#run snap pour point tool on each species shapefile
#use 25 meter snap distance
pour_point = arcpy.sa.SnapPourPoint(species, fa_raster, 25)
print "Snap Pour Point tool executed successfully for " + species
#run watershed tool on pour point and FD raster
watershed = arcpy.sa.Watershed(fd_raster, pour_point)
print "Wastershed tool executed successfully for " + species
species_name = species[:-4]
out_poly = str(species_name) + "_ws.shp"
arcpy.RasterToPolygon_conversion(watershed, out_poly)
print "Raster To Polygon executed successfully for " + species_name
Step 2: delineate watershed
Watershed Polygon Outputs
harperella watershed
small whorled pogonia watershed
Swamp pink watershed
Step 3: buffer pipeline center
Input: pipeline centerline shapefile
Output: 500m buffer polygon shapefile
Code snippet:
#buffer shapefile for hypothetical pipeline project
pipepline = path + "/sample_pipeline.shp"
buff_pipe = path + "/pipe_buff500m.shp"
arcpy.Buffer_analysis(pipepline, buff_pipe, 500)
Step 4: find intersection between pipeline and watersheds
Inputs: list of watershed shapefiles, buffered pipeline shapefile
Output: intersection polygon shapefiles for each species
Code snippet:
#Create loop that iterates through list of watershed shapefiles and runs
#intersect function with buffered shapefile
#name each output file uniquely using part of input file path
for watershed in watershed_List:
watershed_name = watershed[:-4]
out_feature = str(watershed_name) + "_intersect_pipe.shp"
arcpy.Intersect_analysis([watershed, buff_pipe], out_feature)
print "Intersection of watershed and pipeline calculated for " +watershed_name
Step 4: find intersection between pipeline and watersheds
Intersection of swamp
pink watershed and
pipeline buffer
Intersection of harperella
watershed and pipeline
buffer
Note: no polygons for swp
because no
intersection with pipeline
Debugging/challenges/user inputs
Debugging strategies:
- entire code placed inside try/except statement
- print statements throughout to track progress of program
- small raster used for building script and provided as
sample data
- test in small snippets
Challenges:
- creating unique files names in for loops
- making sure the data from different sources was projected
properly
User input:
- user is asked to input their workspace
- user is also asked to input the file path for where the
sample data is stored, and where the output data will go
Complete Code: part I
############################################################
#Stephenson_FinalProject.py
#Created on 6/10/17 by Chelsey Stephenson for GEOG 562
#purpose: This program serves to subset occurrence data
#from a large dataset, delineate watersheds for those
#occurrences, and find the intersection of watersheds with
#development project footprints
############################################################
#place code inside try-except statement
#place print statements throughout to track progress of
program
nhp_data = path + "/sample_NHP_all.shp"
if arcpy.Exists(nhp_data):
print "NHP shapefile exists"
else:
print "NHP shapefile does not exist"
#use select analysis function to subset harperella occurrences from 2012
onward
harp_only = path + "/harp_nhp.shp"
where_clause = '"CMN_name" = \'harperella\' AND "YEAR" > 2011'
arcpy.Select_analysis(nhp_data, harp_only, where_clause)
print "harp select complete"
try:
#import arcpy, check if spatial analyst is enabled
#allow script to run w/o deleting intermediate files
#ask user to input their workspace
import arcpy
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
arcpy.env.workspace = raw_input("Enter workspace:")
#ask user to input path to sample data and output data
#use this path to create paths to output files, so user only
#needs to input once
path = raw_input("Enter path to folder where sample data
exists and outputs will be stored:")
#assign variable to NHP input data
#check if data exists
#do the same for small whorled pogonia (swp)
swp_only = path + "/swp_nhp.shp"
where_clause = '"CMN_name" = \'small whorled pogonia\' AND "YEAR" > 2011'
arcpy.Select_analysis(nhp_data, swp_only, where_clause)
print "swp select complete"
#for swamp pink
swampPink_only = path + "/swampPink_nhp.shp"
where_clause = '"CMN_name" = \'swamp pink\' AND "YEAR" > 2011'
arcpy.Select_analysis(nhp_data, swampPink_only, where_clause)
print "swamp pink select complete"
#place these new shapefiles into a list
spp_List = [harp_only, swp_only, swampPink_only]
print spp_List
#place DEM in variable, check if exists
dem_raster = path + "/sample_dem"
if arcpy.Exists(dem_raster):
print "dem raster exists"
else:
print "dem raster doesn't exist"
Complete Code: part II
#use Fill tool to create fill raster
fill_raster = arcpy.sa.Fill(dem_raster)
print "Fill tool executed successfully"
#use Flow Direction tool on fill raster to create FD raster
fd_raster = arcpy.sa.FlowDirection(fill_raster)
print "Flow Direction tool executed successfully"
#use Flow Accumulation tool on FD raster to create FA raster
fa_raster = arcpy.sa.FlowAccumulation(fd_raster)
print "Flow Accumulation tool executed successfully"
#create for loop that iterates through spp_List, creating pour points
#raster for each species and running the watershed tool
#set optional snap distance parameter to 25 meters
for species in spp_List:
pour_point = arcpy.sa.SnapPourPoint(species, fa_raster, 25)
print "Snap Pour Point tool executed successfully for "+ species
#run watershed tool on pour point and FD raster
watershed = arcpy.sa.Watershed(fd_raster, pour_point)
print "Wastershed tool executed successfully for " + species
#run Raster To Polygon tool to create polygon from watershed raster
#each output shapefile needs a unique name that represents the input
#remove ".shp" from file paths and use that to name new file by
#concatenating "_ws.shp" on the end
#Use simplify option to speed up processing
species_name = species[:-4]
out_poly = str(species_name) + "_ws.shp"
field = "VALUE"
arcpy.RasterToPolygon_conversion(watershed, out_poly, "SIMPLIFY", field)
print "Raster To Polygon executed successfully for " + species_name
Complete Code: part III
#Create list of outputs from watershed tool
harp_ws = path + "/harp_nhp_ws.shp"
swp_ws = path + "/swp_nhp_ws.shp"
swampPink_ws = path + "/swampPink_nhp_ws.shp"
watershed_List = [harp_ws, swp_ws, swampPink_ws]
print watershed_List
#buffer shapefile for hypothetical pipeline project
pipepline = path + "/sample_pipeline.shp"
buff_pipe = path + "/pipe_buff500m.shp"
arcpy.Buffer_analysis(pipepline, buff_pipe, 500)
print "Pipeline buffered 500m"
#Create loop that iterates through list of watershed shapefiles and runs
#intersect function with buffered shapefile
#name each output file uniquely using part of input file path
for watershed in watershed_List:
watershed_name = watershed[:-4]
out_feature = str(watershed_name) + "_intersect_pipe.shp"
arcpy.Intersect_analysis([watershed, buff_pipe], out_feature)
print "Intersection of watershed and pipeline calculated for " + watershed_name
print "Program ran successfully"
except:
print arcpy.GetMessages()
Note: Query criteria, file names, snap distance,
and buffer distance are all built into this
program. However, the script could easily be
adjusted to accommodate other datasets, query
parameters, development projects, etc. Thanks
for watching!