Focal weights matrix
focalWeight.RdCalculate focal ("moving window") weight matrix for use in the focal function. The sum of the values adds up to one.
Usage
focalWeight(x, d, type=c('circle', 'Gauss', 'rectangle'), fillNA=FALSE)Arguments
- x
Raster* object
- d
numeric. If
type=circle, the radius of the circle (in units of the CRS). Iftype=rectanglethe dimension of the rectangle (one or two numbers). Iftype=Gaussthe size of sigma, and optionally another number to determine the size of the matrix returned (default is 3 times sigma)- type
character indicating the type of filter to be returned
- fillNA
logical. If
TRUE, zeros are set toNAsuch that they are ignored in the computations. Only applies totype="circle"
Value
matrix that can be used in focal
Examples
r <- raster(ncols=180, nrows=180, xmn=0, crs="+proj=utm +zone=1")
# Gaussian filter for square cells
gf <- focalWeight(r, .5, "Gauss")
focalWeight(r, 2, "circle", fillNA=TRUE)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] NA NA 0.07692308 NA NA
#> [2,] NA 0.07692308 0.07692308 0.07692308 NA
#> [3,] 0.07692308 0.07692308 0.07692308 0.07692308 0.07692308
#> [4,] NA 0.07692308 0.07692308 0.07692308 NA
#> [5,] NA NA 0.07692308 NA NA