library(rstac)
library(dplyr)
library(gdalcubes)
library(stars)
library(tmap)
s = stac("https://io.biodiversite-quebec.ca/stac/")
items <- s |> stac_search(collections = "colombia_forests", limit = 1000) |>
post_request()
for (i in 1:length(items$features)){
items$features[[i]]$assets[[1]]$roles='data'
}
#Load an image_collection
st <- stac_image_collection(items$features, asset_names='data')
#build cube
bbox <- tibble(xmin = 491004.9 , ymin = 1110923.9, xmax = 1127106.8, ymax = 1858834.6)
v <- cube_view(srs = "EPSG:3116", extent = list(t0 = "2018-01-01", t1 = "2018-12-31",
left = bbox$xmin, right =bbox$xmax, top = bbox$ymax, bottom = bbox$ymin),
dx=1000, dy=1000, dt="P1Y",
aggregation = "first",
resampling = "mode")
rc <- raster_cube(st, v)
rc_aggr <- rc |> aggregate_space(dx=100, dy=100, method = "mean", fact = NULL)
sr_aggr <- rc_aggr |> st_as_stars()
tm_shape(sr_aggr) + tm_raster(style="cat")