# 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"), quiet = TRUE)
}
L8.col = image_collection(file.path(tempdir(), "L8.db"))
v = cube_view(srs="EPSG:32618", dy=1000, dx=1000, dt="P1M",
aggregation = "median", resampling = "bilinear",
extent=list(left=388941.2, right=766552.4,
bottom=4345299, top=4744931,
t0="2018-01-01", t1="2018-04-30"))
L8.cube = raster_cube(L8.col, v)
L8.cube = select_bands(L8.cube, c("B04", "B05"))
L8.ndvi = apply_pixel(L8.cube, "(B05-B04)/(B05+B04)", "NDVI")
L8.ndvi
if (gdalcubes_gdal_has_geos()) {
if (requireNamespace("sf", quietly = TRUE)) {
# create 50 random point locations
x = runif(50, v$space$left, v$space$right)
y = runif(50, v$space$bottom, v$space$top)
t = sample(seq(as.Date("2018-01-01"),as.Date("2018-04-30"), by = 1),50, replace = TRUE)
df = sf::st_as_sf(data.frame(x = x, y = y), coords = c("x", "y"), crs = v$space$srs)
# 1. spatiotemporal points
extract_geom(L8.ndvi, df, datetime = t)
# \donttest{
# 2. time series at spatial points
extract_geom(L8.ndvi, df)
# 3. summary statistics over polygons
x = sf::st_read(system.file("nycd.gpkg", package = "gdalcubes"))
zstats = extract_geom(L8.ndvi,x, FUN=median, reduce_time = TRUE, merge = TRUE)
zstats
plot(zstats["NDVI"])
# }
}
}
Run the code above in your browser using DataLab