raster_focal: Wrapper for 'raster::focal' on 'stars' objects

Description Usage Arguments Value Examples

View source: R/raster_focal.R

Description

This is a wrapper around raster::focal, to apply the function on stars objects without needing to convert to and from a Raster* object.

Usage

1
raster_focal(x, w, fun, na.rm = FALSE)

Arguments

x

A stars object

w

A matrix of weights (the moving window), e.g. a 3 by 3 matrix with values 1

fun

A function. The function fun should take multiple numbers, and return a single number

na.rm

If TRUE, NA will be removed from focal computation. Default is FALSE

Value

A stars object with the filtered output

Examples

1
2
3
4
5
6
7
8
library(stars)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
r = read_stars(tif)
r = r[, , , 1:2]
w = matrix(1, ncol = 7, nrow = 7)
r_focalmean7 = raster_focal(r, w, mean)
plot(r)
plot(r_focalmean7)

michaeldorman/geobgu documentation built on Jan. 6, 2021, 3:57 p.m.