Skip to content

Instantly share code, notes, and snippets.

@debboutr
Created September 8, 2016 22:25
Show Gist options
  • Save debboutr/8f7dbe16a113c01b4a9cbc5e1a9080d6 to your computer and use it in GitHub Desktop.
Save debboutr/8f7dbe16a113c01b4a9cbc5e1a9080d6 to your computer and use it in GitHub Desktop.
import arcpy, os, sys
from arcpy import env
inputs = {'CA':['18'],'CO':['14','15'],'GB':['16'],'GL':['04'],'MA':['02'],'MS':['05','06','07','08','10L','10U','11'],'NE':['01'],'PN':['17'],'RG':['13'],'SA':['03N','03S','03W'],'SR':['09'],'TX':['12']}
# process one coordinate at a time, locating routes for all hydroregions before looping to next coordinate set
# note that once the flowlines are converted into routes, all attribute information will get dropped, we will process the Locate Routes tool again to determine COMID (to get to stream order) for all sites that fail the checks
sites = 'D:/Projects/WEMAP_WSA/SplitCatsNAD83/xyLayer_join.shp'
NHD_dir = "D:/NHDPlusV21"
for i in inputs:
for unitID in inputs[i]:
print unitID
arcpy.MakeFeatureLayer_management(sites, "sites", "\"HYDROREG\" = '%s'" % (unitID))
flowlines= NHD_dir + "/NHDPlus" + i + "/NHDPlus" + unitID + "/NHDSnapshot/Hydrography/NHDFlowline.shp"
# Process: Locate Features Along Routes
out_events = "D:/Projects/WEMAP_WSA/SplitCatsNAD83/LinearEvents2/event_features_reg" + unitID + ".dbf"
Output_Event_Table_Properties = "RID POINT MEAS"
if not arcpy.Exists(out_events):
arcpy.LocateFeaturesAlongRoutes_lr("sites", flowlines, "REACHCODE", "3000 Meters", out_events, Output_Event_Table_Properties, "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
# Process: Make Route Event Layer
arcpy.MakeRouteEventLayer_lr(flowlines, "REACHCODE", out_events, "rid POINT meas", "RouteEvents", "", "NO_ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
out_features = "D:/Projects/WEMAP_WSA/SplitCatsNAD83/LinearEvents2/lr_features_reg" + unitID + ".shp"
if not arcpy.Exists(out_features):
arcpy.CopyFeatures_management("RouteEvents",out_features) #save as shapefile
arcpy.Delete_management("sites")
arcpy.Delete_management("RouteEvents")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment