safe_getMetadata: Get information from S2 file name or metadata

Description Usage Arguments Value Note Author(s) Examples

Description

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.

Usage

1
2
3
4
5
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).

info

(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).

abort

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.

Note

License: GPL 3.0

Author(s)

Luigi Ranghetti, phD (2017, 2018) ranghetti.l@irea.cnr.it

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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")

# Return some specific information without scanning files
safe_getMetadata(s2_examplename, info="nameinfo")[c("level", "id_tile")]

# 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"]]

## 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)


## End(Not run)

pobsteta/theia2r documentation built on May 25, 2019, 2:21 p.m.