Calculate values for the neighborhood of focal cells using a matrix of weights
Usage
focalFilter(x, filter, fun=sum, filename="", ...)
Arguments
x
A RasterLayer object
filter
a matrix of weights. See Details
fun
a function to apply to the product of the matrix of weights and the values
filename
Output filename for a new raster
...
additional arguments. See Details.
Value
A new RasterLayer object (in the R environment), and in some cases the side effect of a new file on disk.
Details
focalFilter uses a matrix of weights for the neigbhorhood of the focal cells, together with a function (normally sum).
For example, filter=matrix(1/9, nrow=3, ncol=3) would be equivalent to mean with ngb=3 in the focal function.
Gaussian filter:
filter=matrix(c(1,2,3,2,1,2,3,4,3,2,3,4,5,4,3,2,3,4,3,2,1,2,3,2,1), nrow=5)/65
Laplacian filter:
filter=matrix(c(0,1,0,1,-4,1,0,1,0), nrow=3)
Sobel filter:
filter=matrix(c(1,2,1,0,0,0,-1,-2,-1) / 4, nrow=3)
Another example:
filter=matrix(c(0,0,0,0,1,1,0,1,1), nrow=3) and fun=max returns the max value for the lower-rigth corner of a 3x3 matrix
around a focal cell
The following additional arguments can be passed, to replace default values for this function
rll{
overwrite Logical. If TRUE, "filename" will be overwritten if it exists
format Character. Output file type. See writeRasterdatatype Character. Output data type. See dataTypeprogress Character. "text", "window", or "" (the default, no progress bar)
}