Python script for watershed delineation with the USGS NLDI API

In November 2022, I posted a tutorial on how to use the US Geological Survey’s web service NLDI to delineated watersheds in the continental United States. Since then, they updated the API, and that old code no longer works. Here is an updated Python script. I’m using the library pynhd, which gives convenient access to the NLDI. You could also use the API directly with the requests library.

This NLDI gives access to data from the National Hydrography Dataset Plus version 2. This is an older version of the NHD that is no longer being updated. At this time, the USGS does not have an API to access the latest version of its geodata, the 3DHP. So if you wanted to use those data for watershed delineation, I suppose you would have to download the data and use GIS or write your own routines.

Let me know what you think. Would you be interested in a Python package that you could install with pip? What kind of output is most useful?

Download the script here: https://gist.github.com/mheberger/9b99aa7c185bbb070c9eff7f8e497091