IvorM
IvorM

Reputation: 31

R terra::flowAccumulation(terrain("flowdir")) fails to create valid river network

I want to create a river network using R Terra, instead of QGIS PCRaster.

I tried with the functions flowAccumulation and terrain("flowdir") on the Luxembourg DEM example provided in the package. The outcome is a disconnected river network.

terra documentation code example:

elev <- rast(system.file('ex/elev.tif',package="terra"))
flowdir <- terrain(elev,"flowdir")
weight <- cellSize(elev,unit="km")
flowacc_weight <- flowAccumulation(flowdir,weight)
flowacc  <- flowAccumulation(flowdir)
plot(flowacc)

River network is disconnected

Using the same DEM in QGIS with PCRaster functions, one gets: PCRaster FlowAcc

The issue is when there are two equal elevation neighbors: Top Row: DEM; Bottom Row: FlowAcc

Does anyone have experience with this issue or ideas how to solve it?

elev_A <- c(78, 72, 69, 71, 58, 49,
          74, 67, 56, 49, 46, 50,
          69, 53, 44, 37, 38, 48,
          64, 58, 55, 22, 31, 24,
          68, 61, 47, 34, 16, 19,
          74, 53, 34, 34, 11, 12) |> matrix(ncol = 6, byrow = TRUE) |> rast()

elev_B <- c(78, 72, 69, 71, 58, 49,
          74, 67, 56, 49, 46, 50,
          69, 53, 44, 37, 38, 48,
          64, 58, 55, 22, 31, 24,
          68, 61, 16, 34, 16, 19,
          74, 53, 34, 34, 11, 12) |> matrix(ncol = 6, byrow = TRUE) |> rast()

Upvotes: 3

Views: 73

Answers (0)

Related Questions