Skip to content

hacking rstac queries #3

@mdsumner

Description

@mdsumner
mgrs_codes <- c("MGRS-20LKP", "MGRS-04QGH")
# Query all 136 estinel tiles at once (or in batches)
stac("https://earth-search.aws.element84.com/v1") %>%
  stac_search(
    collections = "sentinel-2-c1-l2a",
    datetime = "2025-01-01T00:00:00Z/2025-12-31T23:59:59Z"
  ) %>%
  ext_query(`grid:code` %in% mgrs_codes) %>%
  post_request() %>%
  items_fetch()  # get all pages

So the body is just a list that gets JSON-encoded. You can build that directly:

rbody <- list(
  collections = list("sentinel-2-c1-l2a"),
  datetime = "2025-01-01T00:00:00Z/2025-12-31T23:59:59Z",
  limit = 300,
  query = list(
    `grid:code` = list(`in` = c("MGRS-20LKP", "MGRS-04QGH"))
  )
)

# As JSON
jsonlite::toJSON(body, auto_unbox = TRUE, pretty = TRUE)
And POST it yourself:
rhttr::POST(
  "https://earth-search.aws.element84.com/v1/search",
  body = body,
  encode = "json"
) %>% httr::content()

For a GET-style URL (if sds::stacit needs that), the query param encoding would be:

rquery_param <- list(`grid:code` = list(`in` = c("MGRS-20LKP", "MGRS-04QGH")))
query_json <- jsonlite::toJSON(query_param, auto_unbox = TRUE)

url <- paste0(

"https://earth-search.aws.element84.com/v1/search",
  "?collections=sentinel-2-c1-l2a",
  "&datetime=2025-01-01T00:00:00Z/2025-12-31T23:59:59Z",
  "&limit=300",
  "&query=", URLencode(query_json, reserved = TRUE)
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions