if(interactive()){
library(sf)
my_key <- Sys.getenv("spectator_earth_api_key")
# get the New York City Central Park shape as area of interest
dsn <- system.file("extdata", "centralpark.geojson", package = "spectator")
boundary <- sf::read_sf(dsn, as_tibble = FALSE)
# search for May 2021 Sentinel 2 images
catalog <- SearchImages(aoi = boundary, satellites = "S2",
date_from = "2021-05-01", date_to = "2021-05-30",
footprint = FALSE, api_key = my_key)
# get the id of the image with minimal cloud coverage
best_id <- catalog[order(catalog$cloud_cover_percentage), ][1, "id"]
# get the high resolution image of the Central Park
img <- GetHighResolutionImage(aoi = boundary, id = best_id, bands = c(4, 3, 2),
width = 1024, height = 1024,
file = tempfile(pattern = "img", fileext = ".jpg"),
api_key = my_key)
}
Run the code above in your browser using DataLab