query_points: Query data cube values at irregular spatiotemporal points

Description Usage Arguments Details Value Examples

View source: R/query_points.R

Description

This function will overlay provided spatiotemporal points with a data cube and return all band values of the cells for each query point, as a data.frame where rows correspond to points and columns represent bands. If needed, point coordinates are automatically transformed to the SRS of the data cube.

Usage

1
query_points(x, px, py, pt, srs)

Arguments

x

source data cube

px

vector of x coordinates

py

vector of y coordinates

pt

vector of date/ time coordinates

srs

spatial reference system string identifer (as GDAL understands)

Details

Date and time of the query points can be provided as vector of class character, Date, or POSIXct.

Value

a data.frame with one row per point and one column per data cube band or variable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# create image collection from example Landsat data only 
# if not already done in other examples
if (!file.exists(file.path(tempdir(), "L8.db"))) {
  L8_files <- list.files(system.file("L8NY18", package = "gdalcubes"),
                         ".TIF", recursive = TRUE, full.names = TRUE)
  create_image_collection(L8_files, "L8_L1TP", file.path(tempdir(), "L8.db")) 
}
L8.col = image_collection(file.path(tempdir(), "L8.db"))
v = cube_view(extent=list(left=388941.2, right=766552.4, 
              bottom=4345299, top=4744931, t0="2018-01-01", t1="2018-12-02"),
              srs="EPSG:32618", nx = 497, ny=526, dt="P14D")
L8.cube = raster_cube(L8.col, v) 
L8.rgb = select_bands(L8.cube, c("B02", "B03", "B04"))

x = seq(from = 388941.2, to = 766552.4, length.out = 10)
y = seq(from = 4345299, to = 4744931, length.out = 10)
t = seq(as.Date("2018-01-01"), as.Date("2018-12-02"), length.out = 10 )

query_points(L8.rgb, x, y, t, srs(L8.rgb))

gdalcubes documentation built on Oct. 28, 2021, 5:06 p.m.