The function safe_getMetadata() scans a Sentinel2 product (main path, granule path, main / granule xml file or GDAL object) 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", abort = TRUE)

rm_invalid_safe(s2)

safe_isvalid(s2, info = "fileinfo")

## Arguments

s2 A Sentinel-2 product, being both a character (path of an existing product, or simply product name) or python object of class osgeo.gdal.Dataset. This input parameter can be the main path of a S2 file, the path of the xml with metadata, the path of a single granule, the xml path of a single granule, or a 'osgeo.gdal.Dataset' object (obtained reading the product with python). If the product does not exist locally, the function can run only with option info = "nameinfo" (see below). (optional) A character vector with the list of the metadata which should be provided. Accepted values are: "all" (default): all the retrevable metadata are provided; "fileinfo": only the metadata obtained by scanning the file name and product structure (without opening it with GDAL) are provided. "nameinfo": only the metadata obtained by scanning the file name are provided (it is faster and there is no need to have downloaded yet the file). a vector of single specific information (one or more from the followings): "prod_type" ('singlegranule' or 'product'); "version" ('old' or 'compact'); "tiles" (vector with the tiles ID available in the product); "utm" (vector with the UTM zones used in the product); "xml_main" (name of the main XML file with metadata); "xml_granules" (names of the XML with granule metadata); "level" ('1C' or '2A'); "creation_datetime", "id_tile", "mission", "centre", "file_class", "id_orbit", "orbit_number", "sensing_datetime", "id_baseline": metadata speficic of the product type and version (they are returned only if obtainable for the specified input); "clouds", "direction", "orbit_n", "preview_url", "proc_baseline", "level", "sensing_datetime", "nodata_value", "saturated_value": information retrieved from the metadata stored in the XML file. In this version, querying for specific elements requires the product to be present in the filesystem; in future this will be changed (see the second example for a workaround to scan for specific elements without needing the file to have been downloaded). Logical parameter: if TRUE (default), the function aborts in case prod_type is not recognised; if FALSE, a warning is shown.

## Value

safe_getMetadata() returns a list of the output metadata;

rm_invalid_safe() returns TRUE if the s2 product was removed, FALSE elsewhere.

safe_isvalid() returns TRUE if the product is a valid SAFE, FALSE if not.

License: GPL 3.0

## Examples

# Define product name
s2_examplename <-
"/path/of/the/product/S2A_MSIL1C_20170603T101031_N0205_R022_T32TQQ_20170603T101026.SAFE"

# Return only the information retrevable from the file names (files are not scanned)
safe_getMetadata(s2_examplename, info="nameinfo")#> $prod_type #> [1] "product" #> #>$version
#> [1] "compact"
#>
#> $mission #> [1] "2A" #> #>$level
#> [1] "1C"
#>
#> $sensing_datetime #> [1] "2017-06-03 10:10:31 UTC" #> #>$id_baseline
#> [1] "0205"
#>
#> $id_orbit #> [1] "022" #> #>$id_tile
#> [1] "32TQQ"
#>
#> $creation_datetime #> [1] "2017-06-03 10:10:26 UTC" #> # Return some specific information without scanning files safe_getMetadata(s2_examplename, info="nameinfo")[c("level", "id_tile")]#>$level
#> [1] "1C"
#>
#> \$id_tile
#> [1] "32TQQ"
#>
# Return a single information without scanning files
# (in this case, the output is a vector instead than a list)
safe_getMetadata(s2_examplename, info="nameinfo")[["level"]]#> [1] "1C"
# NOT RUN {
# Return all the available information
safe_getMetadata(s2_examplename)

# Return some specific information
safe_getMetadata(s2_examplename, info=c("tiles", "level", "id_tile"))

# Return a single information
safe_getMetadata(s2_examplename, info="clouds")

# Delete it if it is not recognised
rm_invalid_safe(s2_examplename)

# }