Skip to content

Instantly share code, notes, and snippets.

@cboettig
Created December 10, 2022 18:44
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/0945cf3f59ed1dc055c425fb620a826b to your computer and use it in GitHub Desktop.
Save cboettig/0945cf3f59ed1dc055c425fb620a826b to your computer and use it in GitHub Desktop.
# remotes::install_github("OldLipe/rstac@b-0.9.1")
# remotes::install_github("appelmar/gdalcubes_R")
# remotes::install_github("r-spatial/stars")
library(tidyverse)
library(rstac)
library(gdalcubes)
library(tmap)
library(stars)
data(World) #polygons
box <- World |> filter(name == "Brazil") |> pull(geometry) |> st_bbox()
matches <-
stac("https://planetarycomputer.microsoft.com/api/stac/v1") |>
stac_search(collections = "modis-13Q1-061",
datetime = "2022-01-01/2022-03-01",
bbox = c(box)) |>
get_request() |>
items_fetch() |>
items_sign(sign_fn = sign_planetary_computer())
cube <- gdalcubes::stac_image_collection(matches$features,
asset_names = "250m_16_days_NDVI",
duration = "start")
## let's do a 1 yr average
v <- cube_view(srs = "EPSG:4326",
extent = list(t0 = "2022-01-01", t1 = "2022-12-01",
left = box[1], right = box[3],
top = box[4], bottom = box[2]),
dx = 0.2, dy = 0.2, dt= "P1Y",
aggregation = "mean", resampling = "near"
)
ndvi <- raster_cube(cube,v) |> st_as_stars()
tm_shape(ndvi) + tm_raster()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment