gdalcubes
gdalcubes copied to clipboard
Error in stac_image_collection depending on start and end dates
Thanks for the great package!
The code below querying Sentinel data works perfectly for one date range (1-31 October 2019) but not for another (1-30 September 2019).
The September query finds items and the metadata seem valid, but the call to stac_image_collection
results in this error:
Error in data.frame(id = 1:length(bands), name = bands, type = "", offset = NA, :
arguments imply differing number of rows: 2, 0, 1
The problem seems to occur with this line in the stac_image_collection
function:
bands_df = data.frame(id = 1:length(bands), name = bands,
type = "", offset = NA, scale = NA, unit = "", nodata = "",
stringsAsFactors = FALSE)
When running with the September date range, bands
is NULL
at this point, whereas with the October date range bands
has been populated.
Here is the test code to reproduce the error...
library(sf)
library(gdalcubes)
library(rstac)
library(glue)
# Bees Nest fire bounds (NSW Lambert / GDA94)
bbox_3308 <- st_bbox( c(xmin=9788000, ymin=4806000, xmax=9849000, ymax=4854000) )
poly_3308 <- st_as_sfc(bbox_3308)
st_crs(poly_3308) <- 3308
bbox_wgs84 <- poly_3308 |>
st_transform(4326) |>
st_bbox()
bbox_wgs84
# This date range doesn't work. We get an error from the `stac_image_collection` function (a few lines below)
start_date <- "2019-09-01"
end_date <- "2019-09-30"
# Using this date range for the following month works fine...
# start_date <- "2019-10-01"
# end_date <- "2019-10-31"
s <- stac("https://earth-search.aws.element84.com/v0")
items <- s |>
stac_search(collections = "sentinel-s2-l2a-cogs",
bbox = as.numeric(bbox_wgs84),
datetime = glue("{start_date}/{end_date}")) |>
post_request() |>
items_fetch(progress = FALSE)
cat("Found", length(items$features), "items")
items.sf <- items_as_sf(items)
View(items.sf)
s2_collection <- stac_image_collection(items$features,
property_filter = function(x) {x[["eo:cloud_cover"]] < 10})