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

st_extract

Extract cell values at point locations


Description

Extract cell values at point locations

Usage

st_extract(x, ...)

## S3 method for class 'stars'
st_extract(
  x,
  pts,
  ...,
  bilinear = FALSE,
  time_column = attr(pts, "time_column") %||% attr(pts, "time_col"),
  interpolate_time = bilinear
)

Arguments

x

object of class stars or stars_proxy

...

ignored

pts

object of class sf or sfc with POINT geometries

bilinear

logical; use bilinear interpolation rather than nearest neighbour?

time_column

character or integer; name or index of a column with time or date values that will be matched to values of the dimension "time" in x, after which this dimension is reduced. This is useful to extract data cube values along a trajectory; see https://github.com/r-spatial/stars/issues/352 .

interpolate_time

logical; should time be interpolated? if FALSE, time instances are matched using the coinciding or the last preceding time in the data cube.

Details

points outside the raster are returned as NA values.

Value

if x has more dimensions than only x and y (raster), an object of class stars with POINT geometries replacing x and y raster dimensions; otherwise an object of sf with extracted values.

Examples

tif = system.file("tif/L7_ETMs.tif", package = "stars")
r = read_stars(tif)
pnt = st_sample(st_as_sfc(st_bbox(r)), 10)
st_extract(r, pnt)
st_extract(r, pnt) %>% st_as_sf()
st_extract(r[,,,1], pnt)

stars

Spatiotemporal Arrays, Raster and Vector Data Cubes

v0.5-2
Apache License
Authors
Edzer Pebesma [aut, cre] (<https://orcid.org/0000-0001-8049-7069>), Michael Sumner [ctb] (<https://orcid.org/0000-0002-2471-7511>), Etienne Racine [ctb], Adriano Fantini [ctb], David Blodgett [ctb]
Initial release

We don't support your browser anymore

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