Beautiful Watershed Polygons in QGIS

As the title sugests I am showing you, how to create beautiful watershed polygons. We will start with some raster files and use a nice GRASS tool for the main work. But why “beautiful”? As I am a big fan of webmaps and raster analytics tend to result in ugly rectangular structures I am fan of smooth stuff. So check this small tutorial.

The Data

I already mentioned, that we will work with raster data instead of some ugly manual digitization using some maps. In this tutorial we will work with the good old SRTM3 data. Unfortunately the data provided at www.landcover.org are full of missing pixels especially in mountainous regions. I am using height data from CIGAR (cell 39_03 to be exact). So what is the output I am trying to get? I would love to see a basin for each valley in the Alps.

The Computation in QGIS

Compared to ArcGIS, where I remember a ton of steps to calculate watersheds/basins for a raster, the workflow in QGIS is straightforward thanks to the GRASS processing tools. I am using the r.watershed function which only needs a DEM (can have sinks too!) and that’s it. There are tons of other parameters but we will only go by the DEM and the number of pixels for a minimum sized watershed “minimum size of exterior watershed basin”. I am running good with a value of 2000 which means that a basin will be created once at least 2000 cells drain towards a certain pour point. Be careful with this parameter:
Warning: low threshold values will dramactically increase run time and generate difficult to read basin and half_basin results. This parameter also controls the level of detail in the stream segments map.
So here is the interface:
r.watershed Grass
r.watershed interface design with parameters
One more warning: in my current QGIS version 2.12.3 the parameter “Allow only horizontal and vertical flow of water” is checked by default. This made my first usages of the tool useless (check gis.stackexchange.com. If you’re only interested in the basins, choose a file name for the raster “half-basins” or save it after the creation by hand. Uncheck all other exports if you’re not really interested in them! In the end, just press okay and take yourself a coffee. The result might look like this:
half basins QGIS GRASS
half basins created with r.watershed in QGIS

Creating Beautiful Watersheds

Now comes the arty-partsy part. Let’s remove the ugly pixel-structure. Therefore we will use a generalization tool (yes, GENERALIZATION!) together with the Chaikin algorithm. But first we need to convert the raster into a polygon shapefile. Use the r.to.vect algorithm in the toolbox for this purpose:
r.to.vect GRASS QGIS
GRASS’ r.to.vect function in QGIS
and make sure to select “area” as polygon shapefile type twice or you might see some nice lines instead!. Now you have beautiful polygons in your project. Select those of your desired basin and export them as a new shapefile (use “export selected only” in the save as dialog):
valley extraction
GIF showing the valley of interest, the polygons selected and the exported
But here comes the ugly part as you might have a look at the detail:
ugly pixels
ugly edges as a result of the raster data
Now we will take of this by using the v.generalize GRASS function from the processing toolbox:
Chaiken generalization in QGIS with v.generalize
Chaiken generalization in QGIS with v.generalize
As I am a fan of default parameter, let’s only change the number of iterations (I changed it to three) and we will see some nice, smooth polygon borders:
result chaikin
green: prior algorithm, red line: after the algroithm
Check out the result created with QGIS2web:

5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mohammed Habboub
Mohammed Habboub
8 years ago

cool

Carlos Rivas
Carlos Rivas
8 years ago

Nice work!

Diogo Caribé
Diogo Caribé
8 years ago

Is there possibility to use points (intersections of strems) to define the start of catchment area?

Leandro Barros
Leandro Barros
8 years ago

Excelent blog, very interesting!

Valentín Sastre
2 years ago

The QGIS2web result doesn’t load properly. If anyone wants to see the web app with the map go to http://scripts.digital-geography.com/qgis2web_valley/qgis2web_valley