Skip to contents

Samples a raster at points via gdalraster::pixel_extract(), which reads only the blocks containing points. Accepts anything that function accepts (a path or a GDALRaster, passed through untouched) plus a garry LazyRaster/LazyDataset that is already materialised – i.e. one whose graph is a bare source over local files, as materialise() returns.

Usage

extract_points(x, xy, bands = NULL, interp = NULL, ...)

Arguments

x

A LazyRaster, LazyDataset, raster path, or GDALRaster object.

xy

Points: a wk::xy() vector (its CRS supplies xy_srs), or a two-column matrix/data frame as gdalraster expects.

bands

Bands to extract (default all): band names or positions for a LazyDataset or a materialised (band, y, x) cube, file band indices for a path or GDALRaster. Ignored for a single-band LazyRaster, which reads its own band.

interp

Interpolation: NULL/"nearest" (default), "bilinear", "cubic", "cubicspline".

...

Passed to gdalraster::pixel_extract() (krnl_dim, xy_srs, max_ram, as_data_frame).

Value

As gdalraster::pixel_extract(): a matrix, or a data frame with as_data_frame = TRUE. For a garry object, one column per band, named by dataset band, with the band's nodata as NaN and its scale/offset applied, as collect() would return them.

Details

An unmaterialised pipeline is an error, not a silent cube write. Getting pixels onto disk costs real time and space, and the cube is almost always wanted again (for the predict pass, say), so the caller should own that step:

cube <- materialise(pipeline)     # explicit, reusable
vals <- extract_points(cube, pts)

xy may be a wk::xy() point vector, in which case its CRS supplies xy_srs and GDAL reprojects as needed; a matrix or data frame behaves exactly as in gdalraster.

Examples

if (FALSE) { # \dontrun{
pts <- wk::xy(c(512300, 514800), c(4600100, 4601900), crs = "EPSG:32632")
cube <- materialise(composite)
extract_points(cube, pts, interp = "bilinear")
extract_points("composite.tif", pts)   # a path works too
} # }