raster_extract: Wrapper for 'raster::extract' on 'stars' objects

Description Usage Arguments Value Examples

View source: R/raster_extract.R

Description

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

Usage

1
raster_extract(x, y, fun = NULL, na.rm = FALSE)

Arguments

x

A stars object

y

An sf object

fun

A function to summarize raster values, default is NULL

na.rm

If TRUE, NA will be removed before passing raster cells to function. Default is FALSE

Value

A vector, matrix, or list

Examples

1
2
3
4
5
6
7
8
library(stars)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
r = read_stars(tif)
pol = st_sfc(st_buffer(st_point(c(293749.5, 9115745)), 400), crs = st_crs(r))
plot(r[,,,1], reset = FALSE)
plot(pol, add = TRUE, border = "red")
raster_extract(r, pol)
raster_extract(r, pol, fun = mean)

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