safelist
is a format thought to manage lists of SAFE
Sentinel.2 archives.
It is a named character in which names are SAFE codes
(e.g. S2A_MSIL2A_20170507T102031_N0205_R065_T32TNR_20170507T102319.SAFE
),
and values are URLs used to retrieve them from ESA API Hub (e.g.
https://apihub.copernicus.eu/apihub/odata/v1/Products('a4a026c0-db7b-4ba8-9b09-53027ab0d7ab')/$value
).
Some attributes may be included, basically information retrieved by
function s2_list containing product metadata.
Moreover, the attribute online
(retrieved by function safe_is_online
may contain logical values (TRUE for products available for download,
FALSE for products stored in the Long Term Archive).
The class can be generated as an output of function s2_list, or converting
named characters (with the same structures), data.frames or data.tables
(including the columns name
and url
) using as (see examples).
Objects of class safelist
can be converted to named character, data.frames
or data.tables (see examples). The conversion to data.frame / data.table is
useful for reading hidden attributes.
# S3 method for safelist
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
# S3 method for safelist
as.data.table(x, keep.rownames = FALSE, ...)
# S3 method for safelist
as.character(x, ...)
# S3 method for safelist
st_as_sf(x, ...)
# S3 method for safelist
print(x, ...)
License: GPL 3.0
L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020). "sen2r": An R toolbox for automatically downloading and preprocessing Sentinel-2 satellite data. Computers & Geosciences, 139, 104473. doi:10.1016/j.cageo.2020.104473 , URL: https://sen2r.ranghetti.info/.
# \donttest{
pos <- sf::st_sfc(sf::st_point(c(9.85,45.81)), crs = 4326)
time_window <- as.Date(c("2017-05-01", "2017-05-31"))
## Create an object of class safelist
if (is_scihub_configured()) {
list_safe <- s2_list(spatial_extent = pos, time_interval = time_window)
} else {
list_safe <- as(character(), "safelist")
}
list_safe
#> A named vector with 0 SAFE archives.
#> character(0)
class(list_safe)
#> [1] "safelist" "character"
attr(list_safe, "sensing_datetime") # extract an hidden attribute from a safelist
#> NULL
## Convert to other classes
(s2_char <- as.character(list_safe)) # convert to a simple named character
#> character(0)
(s2_df <- as.data.frame(list_safe)) # convert to a data.frame
#> [1] url
#> <0 rows> (or 0-length row.names)
library(data.table)
#>
#> Attaching package: ‘data.table’
#> The following object is masked from ‘package:raster’:
#>
#> shift
(s2_dt <- as.data.table(list_safe)) # convert to a data.table
#> Empty data.table (0 rows and 1 cols): url
library(sf)
if (!is.null(attr(list_safe, "footprint"))) {
(s2_sf <- st_as_sf(list_safe)) # convert to sf
}
## Convert from other classes
as(s2_char, "safelist") # this causes the loss of hidden attributes
#> A named vector with 0 SAFE archives.
#> character(0)
as(s2_df, "safelist") # this (and followings) maintain attributes as columns
#> A named vector with 0 SAFE archives.
#> character(0)
as(s2_dt, "safelist")
#> A named vector with 0 SAFE archives.
#> character(0)
# }