This page was generated from nhd_demo.ipynb. Interactive online version:
NHD Data using HyRiver#
Author |
Affiliation |
|
---|---|---|
Taher Chegini |
Purdue University |
|
Dave Blodgett |
USGS |
This notebook presents capabilities of HyRiver for accessing National Hydrography Dataset (NHDPlus MR and HR) and Watershed Boundary Dataset (WBD). For this purpose, we use the following web services:
NLDI (Network Linked Data Index)
Water Data
3DHP (3D Hydrography Program)
GeoConnex
NHDPlusHR
[1]:
import folium
from pygeohydro import NWIS, WBD
from pynhd import HP3D, NLDI, GeoConnex, NHDPlusHR, WaterData
We select the Wolf River at Langlade, WI (04074950) station for this demonstration.
[2]:
site_id = "04074950"
We start by instantiating the class for these web services. Note that each web service, we usually have to select a desired “layer”. Docstrings of these classes provide more information about the available layers.
[3]:
nldi = NLDI()
nhd_mr = WaterData("nhdflowline_network")
h4_wd = WaterData("wbd04")
h4_wbd = WBD("huc4")
nhd_hr = NHDPlusHR("flowline")
nwis = NWIS()
hp3d = HP3D("flowline")
We can use NLDI to get information about the station and also navigate the NHD MR network up to a certain distance and get the associated NHDPlus MR features.
[4]:
site_feature = nldi.getfeature_byid("nwissite", f"USGS-{site_id}")
upstream_network = nldi.navigate_byid(
"nwissite", f"USGS-{site_id}", "upstreamMain", "flowlines", distance=9999
)
We use Folium to visualize the station and the network.
[5]:
m = upstream_network.explore()
folium.GeoJson(site_feature, tooltip=folium.GeoJsonTooltip(["identifier"])).add_to(m)
m
[5]:
We can also get the drainage basin for this station using NLDI. Additionally, instead of getting the flowlines that are only upstream of the station, we can use the basin’s geometry to obtain all flowlines that are within the bounds of the basin.
[6]:
basin = nldi.get_basins(site_id)
subset = nhd_mr.bygeom(basin.geometry.iloc[0], basin.crs)
[7]:
m = basin.explore(style_kwds={"fillColor": "gray"})
folium.GeoJson(subset, style_function=lambda _: {"color": "blue"}).add_to(m)
m
[7]: