knitr::opts_chunk$set(collapse = TRUE, comment = "#>") has_net <- stacr::has_internet()
library(stacr)
stacr wraps the rstac package with a pipe-friendly, tidy API. Every result is returned as a tibble — never a nested list. The package ships with a catalog registry of known STAC endpoints and supports any STAC API URL.
Key features:
gdalcubes data cubesstac_catalogs() returns a tibble of STAC endpoints bundled with the package:
stac_catalogs()
Query a STAC API to see what data collections are available:
stac_collections("https://earth-search.aws.element84.com/v1")
Search for specific items by collection, bounding box, and date range:
items <- stac_search( url = "https://earth-search.aws.element84.com/v1", collections = "sentinel-2-l2a", bbox = c(-84.5, 38.0, -84.3, 38.2), datetime = "2024-06-01T00:00:00Z/2024-06-30T00:00:00Z", limit = 5 ) items
Each row is one STAC item with an id, collection, datetime, spatial
bbox and geometry, and a list of available assets.
List items directly from a specific collection:
stac_items( url = "https://earth-search.aws.element84.com/v1", collection = "sentinel-2-l2a", limit = 3 )
For raster analysis, use stac_to_cube() to hand off items to
gdalcubes. This requires the gdalcubes
package and uses the raw rstac result from stac_search_raw():
raw <- stac_search_raw( url = "https://earth-search.aws.element84.com/v1", collections = "sentinel-2-l2a", bbox = c(-84.5, 38.0, -84.3, 38.2), limit = 10 ) cube <- stac_to_cube(raw, asset_names = c("red", "green", "blue"))
Visualize search results on an interactive leaflet map (requires leaflet and
sf):
items <- stac_search( url = "https://earth-search.aws.element84.com/v1", collections = "sentinel-2-l2a", bbox = c(-84.5, 38.0, -84.3, 38.2), limit = 5 ) stac_map(items)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.