RmSmallCellChunks: Remove Small Cell Chunks

View source: R/RmSmallCellChunks.R

RmSmallCellChunksR Documentation

Remove Small Cell Chunks

Description

Remove small cell chunks from a raster layer, where a cell chunk is defined as a group of connected cells with non-missing values. The cell chunk with the largest surface area is preserved and all others removed.

Usage

RmSmallCellChunks(r)

Arguments

r

'RasterLayer'. Raster grid layer with cell values.

Value

An object of class 'RasterLayer' giving r with cell values in the smaller cell chunks set to NA.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

Examples

set.seed(2)
r <- raster::raster(ncols = 10, nrows = 10)
r[] <- round(runif(raster::ncell(r)) * 0.7)
r <- raster::clump(r)
r <- raster::ratify(r)
PlotMap(r)

r_new <- RmSmallCellChunks(r)
PlotMap(r_new)

graphics.off()


USGS-R/inlmisc documentation built on Sept. 17, 2022, 2:38 a.m.