Skip to contents

find pits (depressions with no outlet )

Usage

# S4 method for class 'SpatRaster'
pitfinder(x,filename="",...)

Arguments

x

SpatRaster wih flow-direcion. See terrain

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

A SpatRaster-class (raster) map containing value 1 for the pits and value 0 elsewhere.

Author

Emanuele Cordano

Examples


## Creation of a Digital Elevation Model 

elev <- array(NA,c(9,9))
dx <- 1
dy <- 1 
for (r in 1:nrow(elev)) {
  x <- (r-5)*dx
  for (c in 1:ncol(elev)) {
    
    y <- (c-5)*dy
    elev[r,c] <- 10+5*(x^2+y^2)
    }
  } 
  
elev <- cbind(elev,elev,elev,elev) 
elev <- rbind(elev,elev,elev,elev) 
elev <- rast(elev)

## Flow Directions

flowdir<- terrain(elev,v="flowdir")
t(array(flowdir[],rev(dim(flowdir)[1:2])))
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#>  [2,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#>  [3,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#>  [4,]    1    1    1    2    4    8   16   16   16     1     1     1     2
#>  [5,]    1    1    1    1    0   16   16   16   16     1     1     1     1
#>  [6,]    1    1    1  128   64   32   16   16   16     1     1     1   128
#>  [7,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#>  [8,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#>  [9,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [10,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [11,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [12,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [13,]    1    1    1    2    4    8   16   16   16     1     1     1     2
#> [14,]    1    1    1    1    0   16   16   16   16     1     1     1     1
#> [15,]    1    1    1  128   64   32   16   16   16     1     1     1   128
#> [16,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [17,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [18,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [19,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [20,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [21,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [22,]    1    1    1    2    4    8   16   16   16     1     1     1     2
#> [23,]    1    1    1    1    0   16   16   16   16     1     1     1     1
#> [24,]    1    1    1  128   64   32   16   16   16     1     1     1   128
#> [25,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [26,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [27,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [28,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [29,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [30,]    2    2    2    4    4    4    8    8    8     2     2     2     4
#> [31,]    1    1    1    2    4    8   16   16   16     1     1     1     2
#> [32,]    1    1    1    1    0   16   16   16   16     1     1     1     1
#> [33,]    1    1    1  128   64   32   16   16   16     1     1     1   128
#> [34,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [35,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#> [36,]  128  128  128   64   64   64   32   32   32   128   128   128    64
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#>  [1,]     4     4     8     8     8     2     2     2     4     4     4     8
#>  [2,]     4     4     8     8     8     2     2     2     4     4     4     8
#>  [3,]     4     4     8     8     8     2     2     2     4     4     4     8
#>  [4,]     4     8    16    16    16     1     1     1     2     4     8    16
#>  [5,]     0    16    16    16    16     1     1     1     1     0    16    16
#>  [6,]    64    32    16    16    16     1     1     1   128    64    32    16
#>  [7,]    64    64    32    32    32   128   128   128    64    64    64    32
#>  [8,]    64    64    32    32    32   128   128   128    64    64    64    32
#>  [9,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [10,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [11,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [12,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [13,]     4     8    16    16    16     1     1     1     2     4     8    16
#> [14,]     0    16    16    16    16     1     1     1     1     0    16    16
#> [15,]    64    32    16    16    16     1     1     1   128    64    32    16
#> [16,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [17,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [18,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [19,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [20,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [21,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [22,]     4     8    16    16    16     1     1     1     2     4     8    16
#> [23,]     0    16    16    16    16     1     1     1     1     0    16    16
#> [24,]    64    32    16    16    16     1     1     1   128    64    32    16
#> [25,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [26,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [27,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [28,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [29,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [30,]     4     4     8     8     8     2     2     2     4     4     4     8
#> [31,]     4     8    16    16    16     1     1     1     2     4     8    16
#> [32,]     0    16    16    16    16     1     1     1     1     0    16    16
#> [33,]    64    32    16    16    16     1     1     1   128    64    32    16
#> [34,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [35,]    64    64    32    32    32   128   128   128    64    64    64    32
#> [36,]    64    64    32    32    32   128   128   128    64    64    64    32
#>       [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36]
#>  [1,]     8     8     2     2     2     4     4     4     8     8     8
#>  [2,]     8     8     2     2     2     4     4     4     8     8     8
#>  [3,]     8     8     2     2     2     4     4     4     8     8     8
#>  [4,]    16    16     1     1     1     2     4     8    16    16    16
#>  [5,]    16    16     1     1     1     1     0    16    16    16    16
#>  [6,]    16    16     1     1     1   128    64    32    16    16    16
#>  [7,]    32    32   128   128   128    64    64    64    32    32    32
#>  [8,]    32    32   128   128   128    64    64    64    32    32    32
#>  [9,]    32    32   128   128   128    64    64    64    32    32    32
#> [10,]     8     8     2     2     2     4     4     4     8     8     8
#> [11,]     8     8     2     2     2     4     4     4     8     8     8
#> [12,]     8     8     2     2     2     4     4     4     8     8     8
#> [13,]    16    16     1     1     1     2     4     8    16    16    16
#> [14,]    16    16     1     1     1     1     0    16    16    16    16
#> [15,]    16    16     1     1     1   128    64    32    16    16    16
#> [16,]    32    32   128   128   128    64    64    64    32    32    32
#> [17,]    32    32   128   128   128    64    64    64    32    32    32
#> [18,]    32    32   128   128   128    64    64    64    32    32    32
#> [19,]     8     8     2     2     2     4     4     4     8     8     8
#> [20,]     8     8     2     2     2     4     4     4     8     8     8
#> [21,]     8     8     2     2     2     4     4     4     8     8     8
#> [22,]    16    16     1     1     1     2     4     8    16    16    16
#> [23,]    16    16     1     1     1     1     0    16    16    16    16
#> [24,]    16    16     1     1     1   128    64    32    16    16    16
#> [25,]    32    32   128   128   128    64    64    64    32    32    32
#> [26,]    32    32   128   128   128    64    64    64    32    32    32
#> [27,]    32    32   128   128   128    64    64    64    32    32    32
#> [28,]     8     8     2     2     2     4     4     4     8     8     8
#> [29,]     8     8     2     2     2     4     4     4     8     8     8
#> [30,]     8     8     2     2     2     4     4     4     8     8     8
#> [31,]    16    16     1     1     1     2     4     8    16    16    16
#> [32,]    16    16     1     1     1     1     0    16    16    16    16
#> [33,]    16    16     1     1     1   128    64    32    16    16    16
#> [34,]    32    32   128   128   128    64    64    64    32    32    32
#> [35,]    32    32   128   128   128    64    64    64    32    32    32
#> [36,]    32    32   128   128   128    64    64    64    32    32    32

## Pit Detect

pits <- pitfinder(flowdir)

## Application wth example DEM

elev <- rast(system.file('ex/elev.tif',package="terra"))
flowdir <- terrain(elev,"flowdir")

pits <- pitfinder(flowdir)