Skip to content

Instantly share code, notes, and snippets.

@cboettig
Last active May 11, 2023 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cboettig/c3205d798d086e6fdcfe9dce34ec9d8e to your computer and use it in GitHub Desktop.
Save cboettig/c3205d798d086e6fdcfe9dce34ec9d8e to your computer and use it in GitHub Desktop.
library(rstac)
library(gdalcubes)
# let's pick some spatial extent, say, a bbox around "India"
loc <- spData::world |> dplyr::filter(name_long == "India")
box <- sf::st_bbox(loc)
matches <-
stac("https://planetarycomputer.microsoft.com/api/stac/v1") |>
stac_search(collections = "io-biodiversity",
bbox = c(box),
limit = 1000) |>
post_request() |>
items_sign(sign_fn = sign_planetary_computer())
length(matches$features) # 92 seperate assets we will stitch together!
cube <- gdalcubes::stac_image_collection(matches$features, asset_names = "data")
v <- cube_view(srs = "EPSG:4326",
extent = list(t0 = "2017-01-01", t1 = "2020-12-31",
left = box[1], right = box[3],
top = box[4], bottom = box[2]),
nx = 500, ny=500, nt = "P1Y")
Q <- raster_cube(cube,v)
plot(Q, col = viridisLite::magma)
# animate
animate(Q, col = viridisLite::mako, key.pos = 1, save_as = "anim.gif", fps = 1)
@cboettig
Copy link
Author

anim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment