fill_gaps {flexurba} | R Documentation |
Fill gaps in clusters of cells
Description
The function fills gaps with an area smaller than max_gap
. A gap is considered a patch of NA
cells that lies within a cluster of cells with the same value. The implementation of the function relies on the function nngeo::st_remove_holes()
.
Usage
fill_gaps(x, max_gap = 15)
Arguments
x |
SpatRaster |
max_gap |
numeric. Gaps with an area smaller than |
Details
max_gap
has the same unit as the resolution of x
. For example, with a SpatRaster in Mollweide (EPSG:54009
) and a resolution of 1 km², max_gap
is interpreted in km².
Value
SpatRaster
Examples
nr <- nc <- 8
r <- terra::rast(nrows = nr, ncols = nc, ext = c(0, nc, 0, nr), crs = "epsg:25831")
terra::values(r) <- c(
NA, NA, NA, NA, 1, 1, 1, NA,
NA, 2, 2, 2, NA, NA, 1, NA,
NA, 2, NA, 2, 2, NA, 1, 1,
NA, 2, NA, NA, 2, 2, NA, NA,
NA, 2, 2, 2, 2, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA
)
terra::plot(r)
gaps_filled <- fill_gaps(r)
terra::plot(gaps_filled)
[Package flexurba version 0.2.2 Index]