1

Using a DEM, I want to define catchment boundaries for a given location on a river. Basically, what area drains into this point. In ArcMap, I can do that with flowacc and other tools; but I'd like to do that in R. I know how to import a DEM raster in R but that's about it.

2 Answers 2

1

You can do that by using the GRASS package for R: rgrass7

The procedure is decribed in the r.water.outlet man page (link)

1

To complete @Marco's answer, watershed can be done in GRASS through RQGIS3 or done in RSAGA. Of course, you need QGIS, GRASS and SAGA installed on your computer.

Here is an example. The DEM comes from : http://ftp.geogratis.gc.ca/pub/nrcan_rncan/elevation/cdem_mnec/021/

GRASS (through RQGIS3)

library(gdalUtils)
library(RQGIS3)
library(here)
set_env("C:/OSGeo4W64")
qgis_session_info()

gdal_translate(here("data", "cdem_dem_021M.tif"),
               here("temp_files", "dem_temp.tif"),
               projwin = c(-71.2, 47.5, -70.5, 47))
#get_usage(alg = "grass7:r.watershed")
run_qgis(alg = "grass7:r.watershed",
         elevation = here("temp_files", "dem_temp.tif"),
         threshold = 5000,
         drainage = here("temp_files/drain.tif"))
#get_usage(alg = "grass7:r.water.outlet")
bassin_grass <- run_qgis(alg = "grass7:r.water.outlet",
                         input = here("temp_files/drain.tif"),
                         output = here("temp_files/bassin_grass.tif"),
                         coordinates="-70.8837037458,47.0692354224",
                         load_output = TRUE)

produces: enter image description here

SAGA (through RSAGA)

If you're not satisfied with GRASS, do:

library(RSAGA)
rsaga.fill.sinks(in.dem = here("temp_files", "dem_temp.tif"), 
                 out.dem = here("temp_files", "no.sink.sgrd"),
                 out.wshed = here("temp_files", "bassin_saga.sgrd"),
                 method = "wang.liu.2006")
bassin_saga <- raster(here("temp_files", "bassin_saga.sdat"))
bassin_saga[bassin_saga!=1307] <- NA

which produces:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.