This page was generated from nhd_demo.ipynb. Interactive online version: Binder badge

NHD Data using HyRiver#




Taher Chegini

Purdue University

Dave Blodgett


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

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.

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.

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.

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.

m = upstream_network.explore()
folium.GeoJson(site_feature, tooltip=folium.GeoJsonTooltip(["identifier"])).add_to(m)
Make this Notebook Trusted to load map: File -> Trust Notebook

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.

basin = nldi.get_basins(site_id)
subset = nhd_mr.bygeom(basin.geometry.iloc[0],
m = basin.explore(style_kwds={"fillColor": "gray"})
folium.GeoJson(subset, style_function=lambda _: {"color": "blue"}).add_to(m)
Make this Notebook Trusted to load map: File -> Trust Notebook