Improved Flowpath Tracing

Last month, I posted a poll on the Global Watersheds page. The app is getting around 200 users per day, and I was curious to see who is using it and why.

I found out that most of you are just as interested in tracing downstream flowpaths as you are in delineating watersheds. To be honest, I added this feature to the app as a bit of an afterthought.

More detailed flowpaths

Since folks are so interested in downstream flowpaths, I decided to add a couple of new features. You can now use higher-precision mode. (This is enabled by default if you are zoomed in far enough or when you manually enter coordinates).

Previously, the flowpath started at the closest river or stream. Now, the flowpath starts right near the point where you clicked. (Well, starting at the nearest pixel with a downstream neighbor.) The app will trace the flow from the point of origin, going downhill over land until it encounters a stream or river. From there, it flows to the sea or to an inland sink.

Share flowpaths

You can now share or embed your downstream flowpaths. After you’ve created a new flowpath, just click one of the sharing buttons at the left bottom. The link will point to a custom page with your flowpath. To embed a map widget, click the embed button </>, and copy and paste the code into a web page or blog post.

Tracing contaminant flow

Here’s an example of both new features in action. On February 2, 2023, a freight train derailed in East Palestine, Ohio. According to the US Environmental Protection Agency, vinyl chloride and other toxic chemicals were “released to the air, surface soils, and surface waters.”

Based on the EPA reports, the spill occurred at latitude: 40.836° N, longitude: -80.522° W. We can use the Global Watersheds app to find out where water flows downstream from this location. This can help us begin to understand where these chemicals can be transported by water, and what people and ecosystems could be at risk.

As always, if you encounter any bugs using these new features, send me a message!

Some new map options in the Global Watersheds web app

On the Global Watersheds app, I noticed that the OpenTopo map layers were not loading for me at all. I think I may have gone over some kind of limit.

As a workaround, I’ve added a whole bunch of new basemap options. A couple of them only work in certain regions. For example, GeoPortail France only works at higher zoom levels in France, and the USGS topographic maps can only zoom in to the US.

Some of the new basemap options have limits on the number of map tiles they will provide for free. So if one doesn’t work, try a different one. And if you have any feedback, let me know! 🙂

Demo: Use the Global Watersheds API and Python to automatically delineate watersheds

It seems that a few people are discovering the mghydro watershed delineation API. Last Monday, the API handled requests for 9,679 watersheds over the course of a few hours. (Someone is very interested in the watersheds of France!)

One way to use the API is with GIS software, to fetch watershed boundaries and river centerlines from the web app and display them in your desktop GIS. Another use is to automate your requests, rather than using the online map interface. This could be useful if you want to delineate hundreds (or thousands!) of watersheds. However, remember that the results of automated delineation are very often wrong, so you should visually check each one.

Here is a demo in Python of how you could use the API to download watersheds for multiple outlet points. Click on the filename at the bottom to go to Github, where you can download the Jupyter notebook.

The Genesee River Watershed

I grew up a stone’s throw from the Genesee River, in Rochester, New York, but never knew that the river began in far-off Pennsylvania. Exploring watersheds can change the way you view the world.

According to family lore, my ancestors (around the 1820s or 30s?) were headed to the western frontier, but when they got as far as Rochester, the women declared they were hot, dusty, and tired, and this little town with its flour mills and waterfalls suited them just fine.

Full screen: https://mghydro.com/watersheds/shared/F15986.html

As the Genesee flows north through central New York State, it carves out the magnificent Grand Canyon of the East, which you can visit at Letchworth State Park. This was a popular day trip for my family when I was young, and must have influenced my lifelong love of rivers!

The Genesee River gorge in Letchworth State Park, with the historic 1875 Erie Railroad bridge crossing upstream of Upper Falls. Photo by James St. John.

The Los Angeles River Watershed

The Los Angeles Times magazine recently published a fantastic article on the Los Angeles River, exploring its history and plans for its redesign. The author, the Times architecture critic Michael Kimmelman, writes that, “Angelenos live, work and play along it, but know little of its origins.” I think you could say the same about the residents of any city astride a river, great or small.

Aerial view of the Venura Freeway over the Los Angeles River on the border of Burbank and Los Angeles (GPS: 34.155, -118.316). Photo by Adali Schell, LA Times. Where do these troubled waters come from? According to the author, “the headwaters of the Los Angeles River aren’t easy to find.”

However, it has never been easier to find a river’s watershed. I have been delighted by how many Wikipedia articles about rivers contain high-quality watershed maps. Most of these were created for free by amateur cartographers and are free to reuse. Many of them are made by a small handful of contributors. Kmusser and Shannon1, you are unsung watershed heroes!

Map of the Los Angeles River watershed, by USGS and Wikipedia user Shannon1.

One day, maybe every article about a river will have a map of its watershed. This is especially useful when you want to understand more about pollution, flooding, or land use. And might I suggest that it has never been easier to map a watershed thanks to the free Global Watershed App on this site? For example, here is an interactive map of the Los Angeles River watershed created with the app:

Embed an interactive watershed map on your website or blog

I added another feature to the Global Watersheds App. After you’ve mapped a watershed, you can embed an interactive map. On the left side menu, look for the embed button under “Share your watershed.”

You can paste the html code into your website or blog to put a nice embedded map onto your site. You can adjust the size by changing the numbers for height and width in the html.

Here is an example. I embedded the watershed of the Yukon River in Alaska in this post on my WordPress blog. In WordPress, you have to click Add block, then choose the block type “Custom html.” You may see a warning, “This block contains unexpected or invalid content.” I ignored the warning and published the post, and the map appears like it should.

New (experimental) watersheds API

I’ve set up an API for the watersheds app so you can get watersheds even if you’re not using the web app. You just need to provide a carefully formatted URL. There is a separate link for watershed boundaries and for rivers.

The API returns a GeoJSON string that many applications can use. To use it, you need to provide the latitude and longitude of a watershed outlet, and tell it if you want high-precision or low. (Note that if your watershed has an area of over 50,000 km², the app will automatically revert to low-precision, regardless of what you requested.)

Remember that, just like the regular web app, it can take a while for the app to create large watersheds for the first time. (After they’ve been generated once, the result is cached. Making the same request a second or third time should be fast.)

This feature is experimental and subject to change! Drop me a line and tell me if you are using it for something cool.

Base URLs:

https://mghydro.com/app/watershed_api 
https://mghydro.com/app/upstream_rivers_api

Parameters

To be entered as a query string:

lat: a number from -180 to +180
lng: a number from -60 to +85
precision: "low" or "high", without quotes. Optional: if omitted, defaults to "low"

Examples:

https://mghydro.com/app/watershed_api?lat=43.253&lng=-77.609&precision=high
        
https://mghydro.com/app/upstream_rivers_api?lat=43.253&lng=-77.609&precision=high
    

Usage

With the API, you can plug the URL right into QGIS. Choose Layer > Add Layer > Add Vector Layer, then and in the field, “Vector Dataset(s),” add the URL, then click “Add.” Adjust the styles, and you can have something that looks like this:

How to use Python to delineate watersheds in the continental US with USGS web services

I recently tried my hand at using NLDI, the new water data web service from the U.S. Geological Survey. The service provides access to water data from the National Hydrography Dataset (NHD), version 2. I was specifically interested in using the NHD geodata to delineate watersheds. This data was digitized from 1:100,000-scale maps. (There is newer, more detailed data, called NHDPlus HR, for high-resolution, but no web service for these data yet.)

Snake River watershed upstream of the Lower Granite Dam in eastern Washington state (just a location I picked at random for this demo!)

It took me a couple days of tinkering to get the results I wanted, but the results look impressive and seem accurate. You can run the code yourself by downloading one of these files from GitHub Gists. (Or follow along below.)

Hi!

Featured

My name is Matt and I’m a hydrologist, water manager, and computer programmer. Through 2024, I lived in Paris, France with my family, as I recently earned a PhD in hydrology and remote sensing at Sorbonne University.

I created this site to house some projects and maybe a few ideas. Check out the the Global Watersheds web app, which I’m particularly proud of. I think it is by far the fastest and easiest way to find the drainage basin upstream of (almost) any point on Earth.

Thanks for dropping by. Get in touch if you have any comments or are interested in collaborating!