## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
eval_chunks <-
  CopernicusDataspace::dse_has_client_info() &&
  CopernicusDataspace::dse_has_account() &&
  CopernicusDataspace::dse_has_s3_secret()

## ----stac-collections, eval=eval_chunks---------------------------------------
library(CopernicusDataspace)
dse_stac_collections()

## ----queryables, eval=eval_chunks---------------------------------------------
dse_stac_queryables("sentinel-1-grd") |> summary()

## ----stac-search, eval=eval_chunks--------------------------------------------
library(dplyr)
library(sf)

bbox <-
  sf::st_bbox(
    c(xmin = 5.261, ymin = 52.680, xmax = 5.319, ymax = 52.715),
    crs = 4326)

dse_stac_search_request("sentinel-1-grd") |>
  filter(`sat:orbit_state` == "ascending") |>
  arrange("id") |>
  st_intersects(bbox) |>
  collect()

## ----stac-uri, eval=eval_chunks-----------------------------------------------
dse_stac_get_uri(
  asset_id = "S2A_MSIL1C_20260109T132741_N0511_R024_T39XVL_20260109T142148",
  asset = "B01",
  collection = "sentinel-2-l1c"
)

## ----stac-download, eval=FALSE------------------------------------------------
# dse_stac_download(
#   asset_id = "S2A_MSIL1C_20260109T132741_N0511_R024_T39XVL_20260109T142148",
#   asset = "B01",
#   collection = "sentinel-2-l1c",
#   destination = tempdir()
# )

