Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

focalMat

Focal weights matrix


Description

Make a focal ("moving window") weight matrix for use in the focal function. The sum of the values adds up to one.

Usage

focalMat(x, d, type=c('circle', 'Gauss', 'rectangle'))

Arguments

x

SpatRaster

d

numeric. If type=circle, the radius of the circle (in units of the crs). If type=rectangle the dimension of the rectangle (one or two numbers). If type=Gauss the size of sigma, and optionally another number to determine the size of the matrix returned (default is 3*sigma)

type

character indicating the type of filter to be returned

Value

matrix that can be used with focal

Examples

r <- rast(ncol=180, nrow=180, xmin=0)
focalMat(r, 2, "circle")

focalMat(r, c(2,3), "rect")

# Gaussian filter for square cells
gf <- focalMat(r, 1, "Gauss")

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.