Description Usage Arguments Details Value See Also Examples
View source: R/focalMultiBand.R
Apply a spatial filter to a RasterLayer or all layers of a RasterStack or
RasterBrick object. The mathematical operation applied within the
neighborhood can be done by using a function (fun
) or by setting
the weights of the matrix w
.
1 2 3 4 5 6 7 8 9 10 11 12 |
x |
Raster* object or list of Raster* objects. |
w |
Matrix of weights (moving window). A 3x3 windows with weights of 1
would be |
fun |
Function (optional). The function should accept a vector of values
and return a single number (e.g. mean). It should also accept a
|
filename |
Character. Output file name including path to directory and
eventually extension. If |
na.rm |
Logical. If TRUE (default), NAs are removed from computation |
pad |
Logical. IF TRUE, rows and columns are added around |
padValue |
Numeric. Value of |
NAonly |
Logical. If TRUE only cell values that are NA are replaced with the computed focal values. |
keepNA |
Logical. If TRUE (default), NA cells of |
... |
Additional arguments passed to |
If x contains NA values and na.rm = TRUE
is used , using fun
or
w
with weights adjusted to apply equivalent mathematical operation
might not produce the same outputs (in that case using weights would give
wrong results). See the documentation of focal
for
more information.
Also, cells of x with NA values might get a non-NA value assigned when
located in the neighborhood of non-NA cells and na.rm = TRUE
is used.
In that case, setting keepNA = TRUE
(default) ensures that NA cells of x still
have NA values in the output raster.
Raster* object or list of Raster* objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Load raster package
library(raster)
# Open and stack ALS metrics
elev_p95 <- raster(system.file("extdata/examples/ALS_metrics_p95.tif",package="foster"))
cover <- raster(system.file("extdata/examples/ALS_metrics_cov_mean.tif",package="foster"))
Y_vars <- stack(elev_p95,cover)
#Define 3x3 filter with weights of 1
filt <- matrix(1, nrow = 3, ncol = 3)
# Smoothing
Y_vars_smooth <- focalMultiBand(x = Y_vars,
w=filt,
fun=mean,
pad=TRUE,
padValue=NA,
na.rm=TRUE,
keepNA = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.