View source: R/safe_getMetadata.R
safe_getMetadata | R Documentation |
The function safe_getMetadata()
scans a Sentinel2 product
(main path or granule xml file) to retrieve information about the product.
The accessory function rm_invalid_safe()
remove a SAFE archive in the case
it is not recognised by safe_getMetadata()
.
The accessory function safe_isvalid()
scan the SAFE name to understand
if it is a valid SAFE.
safe_getMetadata(
s2,
info = "all",
format = "default",
simplify = TRUE,
abort = TRUE,
allow_oldnames = FALSE
)
rm_invalid_safe(s2, req_res = c("10m", "20m", "60m"), allow_oldnames = FALSE)
safe_isvalid(
s2,
allow_oldnames = FALSE,
check_file = TRUE,
req_res = c("10m", "20m", "60m")
)
s2 |
Sentinel-2 products, which can be:
|
info |
(optional) A character vector with the list of the metadata which should be provided. Accepted values are:
|
format |
Output format, being one of the followings:
|
simplify |
Logical parameter, which applies in case |
abort |
Logical parameter: if TRUE (default), the function aborts
in case some inputs are not recognised, or if some files do not exists
(in case some |
allow_oldnames |
Logical parameter: if TRUE, old (long) name products are managed (metadata are returned, and they are considered valid; if FALSE (default), they are considered as non-supported files. Note that, from sen2r version 1.1.0, oldname products are no more supported within processing chains, so this function is deprecated and no more supported; moreover, it will be removed in next releases. |
req_res |
Character: vector of variable length (0 to 3)
containing the names of the spatial resolution to be checked
(one or more among |
check_file |
Logical: if TRUE (default), the content of the provided paths is checked; if FALSE, only the validity of SAFE names is tested. |
safe_getMetadata()
returns a data.table, a data.frame or a list
(depending on argument format
) with the output metadata;
rm_invalid_safe()
returns a named vector (with the length of s2
) with
TRUE if the s2
product was removed, FALSE elsewhere.
safe_isvalid()
returns a named vector (with the length of s2
) with
TRUE if the product is a valid SAFE, FALSE if not.
License: GPL 3.0
Luigi Ranghetti, phD (2019)
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.cageo.2020.104473")}, URL: https://sen2r.ranghetti.info/.
# Define product name
s2_examplenames <- c(
"S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE",
"S2A_MSIL1C_20190723T101031_N0208_R022_T32TNR_20190723T121220.SAFE"
)
# Return the information retrievable from the file names (files are not scanned)
safe_getMetadata(s2_examplenames, info="nameinfo")
# Return some specific information without scanning files
safe_getMetadata(s2_examplenames, info=c("level", "id_tile"))
# Return a single information without scanning files
# (in this case, the default output is a vector instead than a data.table)
safe_getMetadata(s2_examplenames, info="level")
# Check if the products are valid existing SAFE archives
safe_isvalid(s2_examplenames)
# Check if the product names are valid SAFE names
safe_isvalid(s2_examplenames, check_file = FALSE)
safe_isvalid("invalid_safe_name.SAFE", check_file = FALSE)
## Not run:
# Download a sample SAFE archive (this can take a while)
s2_exampleurl <- c(
"S2B_MSIL2A_20220612T100559_N0400_R022_T32TNR_20220612T132443.SAFE" =
paste0("gs://gcp-public-data-sentinel-2/L2/tiles/32/T/NR/",
"S2B_MSIL2A_20220612T100559_N0400_R022_T32TNR_20220612T132443.SAFE")
)
s2_download(s2_exampleurl, outdir=tempdir())
s2_examplepath <- file.path(tempdir(), names(s2_exampleurl))
# Return all the available information
safe_getMetadata(s2_examplepath)
# Return some specific information
safe_getMetadata(s2_examplepath, info=c("clouds", "direction"))
# Return a single information
safe_getMetadata(s2_examplepath, info="nodata_value")
# Check if the downloaded SAFE is valid
safe_isvalid(s2_examplepath)
# Delete it if it is not recognised
rm_invalid_safe(s2_examplepath)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.