Description Usage Arguments Details Value Author(s) See Also Examples
Applies an areal threshold to a raster layer. A threshold is supplied in square metres (to be generalized in future) and all pixel 'clumps' smaller than this threshold are deleted.
1 2 |
x |
Input raster layer. |
thresh |
Numeric. Areal threshold (in square metres). All pixel clumps smaller than this threshold will be deleted. |
directions |
Numeric. Define pixel neighbours using diagonals ( |
keepzeros |
Logical. Treat zeros as NA's (default option for |
cores |
Numeric. Number of cores to use for parallel processing (only valid if x is a RasterBrick or RasterStack) |
... |
Additional arguments to be passed to |
In all cases, a filename
can be passed to areaSieve
, but the arguments allowed by the ...
differ depending on whether a multi-layered raster object is supplied - in which case writeRaster
is used - or if a single-layered raster is supplied - in which case either mask
or overlay
is used.
areaSieve
is based on the raster::clump
, which by default ignores zeroes (ie. considers them as NA's). To consider zeroes as valid pixel values when applying the sieve, set keepzeroes
to TRUE
.
raster with pixels in clumps smaller than that specified as thresh removed. All spatial parameters and data are otherwise identical to x.
Ben DeVries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # load test raster
data(tura)
# extract the first layer
r <- raster(tura, 1)
# create pixel 'islands' by reassigning some values to NA
r[r < 7500] <- NA
# zoom into extent where pixel islands were generated
e <- extent(c(821958, 822697, 830504, 831070))
plot(r, ext=e)
# apply areaSieve with default threshold of 5000 square metres
rs <- areaSieve(r)
# compare two rasters
op <- par(mfrow=c(1, 2))
plot(r, ext=e, legend=FALSE)
plot(rs, ext=e, legend=FALSE)
par(op)
# same as above, but assign 0 instead of NA
# (ie. simulate a situation where 0's are valid pixel values)
r <- raster(tura, 1)
r[r < 7500] <- 0
# apply areaSieve with default threshold of 5000 square metres and keep zeros
rs <- areaSieve(r, keepzeros = TRUE)
# compare two rasters
op <- par(mfrow=c(1, 2))
plot(r, ext=e, legend=FALSE)
plot(rs, ext=e, legend=FALSE)
par(op)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.