<p>Take a look at the <a href="https://rdrr.io/cran/RSAGA/man/RSAGA-package.html" rel="nofollow noreferrer">RSAGA</a> package on CRAN, or the <a href="https://www.rdocumentation.org/packages/rgdal/versions/1.4-3" rel="nofollow noreferrer">rgdal</a> package. Many of the GIS methods can be done in R but basically act as a wrapper for saga or gdal. RSAGA is likely your best bet for processing terrains for flow analysis. </p>

<p>I also know of <a href="http://ibis.geog.ubc.ca/~rdmoore/Rcode.htm" rel="nofollow noreferrer">Dan Moore from UBC</a> who does a lot of work with R and GIS applications, worth taking a look there and certainly those algorithms can be done in R directly.</p>

<p>There is also another post in the GIS forum on using TauDEM in R, worth taking a look as well. <a href="https://gis.stackexchange.com/questions/84694/flow-accumulation-in-r">TauDEM in R - additional SO post</a></p>

<p>In general, <a href="https://rseek.org/" rel="nofollow noreferrer">rseek</a> is an excellent search engine for exactly this type of problem in case you don't find what you are looking for in those links above. </p>

<p>For actual flood routing, you may be interested in the Height Above Nearest Drainage Model (HAND), which uses the same type of D8 flow accumulation algorithm to build a rapid method for floodplain mapping. Good <a href="https://ideas.repec.org/a/spr/nathaz/v93y2018i2d10.1007_s11069-018-3331-y.html" rel="nofollow noreferrer">paper</a> on that some other 1D methods.</p>

CC BY-SA 4.0
2019-06-03T13:01:57.387Z
2019-06-03T17:53:46.020Z
2019-06-03T17:53:46.020Z
Rob
<p>I have a DEM as shown for which I have determined flow paths using D8 algorithm (My own code) in R. The resulting DEM with the flow paths is also shown. The flow paths are generated in the form of lines with the help of lines function in R, joining the centers of each pixel in the direction of steepest slope. I would like to perform flow routing with flow paths being derived on the DEM. It should be noted that the flow paths are just lines plotted on the DEM using lines function and elevation of the pixels. </p>

<p>Is there any way to perform flow routing for a hypothetical storm event in R?  </p>

<p><a href="https://i.sstatic.net/bsrLy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bsrLy.png" alt="The DEM"></a>
<a href="https://i.sstatic.net/P2BEU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/P2BEU.png" alt="The DEM with flow paths developed"></a> </p>

CC BY-SA 4.0
2019-05-30T19:20:12.347Z
Using R it is probably possible but seems like a bit unintuitive for this work. Did you considered gdal, or GRASS/QGIS or something like this for your task: https://grass.osgeo.org/grass76/manuals/r.carve.html
marsisalie
CC BY-SA 4.0
2019-05-31T03:56:25.933Z
We aren't sure if GDAL or other GIS modules will help in routing, however flowpaths are derived from them. We are restricted to R as of now and would like to know coding routines (if any) for flow routing
M Azharuddin
<hydrology><gis>
Code for DEM based flow routing in R
M Azharuddin
# Code for DEM based flow routing in R

(Asked by: username_0 on 2019-05-30)

I have a DEM as shown for which I have determined flow paths using D8 algorithm (My own code) in R. The resulting DEM with the flow paths is also shown. The flow paths are generated in the form of lines with the help of lines function in R, joining the centers of each pixel in the direction of steepest slope. I would like to perform flow routing with flow paths being derived on the DEM. It should be noted that the flow paths are just lines plotted on the DEM using lines function and elevation of the pixels.

Is there any way to perform flow routing for a hypothetical storm event in R?

[![The DEM](https://i.sstatic.net/bsrLy.png)](https://i.sstatic.net/bsrLy.png)
[![The DEM with flow paths developed](https://i.sstatic.net/P2BEU.png)](https://i.sstatic.net/P2BEU.png)

**Tags:** hydrology, gis

> **Comments:**
> **username_1**: Using R it is probably possible but seems like a bit unintuitive for this work. Did you considered gdal, or GRASS/QGIS or something like this for your task: https://grass.osgeo.org/grass76/manuals/r.carve.html  
> **username_0**: We aren't sure if GDAL or other GIS modules will help in routing, however flowpaths are derived from them. We are restricted to R as of now and would like to know coding routines (if any) for flow routing  

---

## 1 answers

### Answer by username_2 on 2019-06-03. Score: 3

Take a look at the [RSAGA](https://rdrr.io/cran/RSAGA/man/RSAGA-package.html) package on CRAN, or the [rgdal](https://www.rdocumentation.org/packages/rgdal/versions/1.4-3) package. Many of the GIS methods can be done in R but basically act as a wrapper for saga or gdal. RSAGA is likely your best bet for processing terrains for flow analysis.

I also know of [Dan Moore from UBC](http://ibis.geog.ubc.ca/~rdmoore/Rcode.htm) who does a lot of work with R and GIS applications, worth taking a look there and certainly those algorithms can be done in R directly.

There is also another post in the GIS forum on using TauDEM in R, worth taking a look as well. [TauDEM in R - additional SO post](https://gis.stackexchange.com/questions/84694/flow-accumulation-in-r)

In general, [rseek](https://rseek.org/) is an excellent search engine for exactly this type of problem in case you don't find what you are looking for in those links above.

For actual flood routing, you may be interested in the Height Above Nearest Drainage Model (HAND), which uses the same type of D8 flow accumulation algorithm to build a rapid method for floodplain mapping. Good [paper](https://ideas.repec.org/a/spr/nathaz/v93y2018i2d10.1007_s11069-018-3331-y.html) on that some other 1D methods.


---

