This accessory function extract some useful metadata from a vector of raster paths.

raster_metadata(raster_paths, meta = "all", format = "data.table")

Arguments

raster_paths

A vector of raster paths.

meta

Vector with the desired metadata: one or more values among 'res', 'size', 'bbox', 'proj', 'unit', 'outformat', 'type'. Alternatively meta = 'all' (default) allows to return all metadata.

format

One between data.table (default), data.frame and list.

Value

A data.table, data.frame or list of the output metadata.

Note

License: GPL 3.0

Examples

# Define product names examplenames <- c( system.file("tif/L7_ETMs.tif", package="stars"), system.file("nc/bcsd_obs_1999.nc", package = "stars"), system.file("extdata/out/S2A2A_20170703_022_Barbellino_BOA_10.tif", package = "sen2r") ) # \donttest{ # Return metadata as data.table raster_metadata(examplenames)
#> path #> 1: /home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/tif/L7_ETMs.tif #> 2: /home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/nc/bcsd_obs_1999.nc #> 3: /home/lranghetti/share/git/github/ranghetti/sen2r/inst/extdata/out/S2A2A_20170703_022_Barbellino_BOA_10.tif #> valid res.x res.y size.x size.y nbands xmin ymin xmax #> 1: TRUE 28.500 28.500 349 352 6 288776.3 9110729 298722.750 #> 2: TRUE 0.125 0.125 81 33 12 -85.0 33 -74.875 #> 3: TRUE 10.000 10.000 24 42 11 580560.0 5101700 580800.000 #> ymax #> 1: 9120760.750 #> 2: 37.125 #> 3: 5102120.000 #> proj #> 1: +proj=utm +zone=25 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs #> 2: <NA> #> 3: +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs #> unit outformat type #> 1: Meter GTiff Byte #> 2: <NA> netCDF <NA> #> 3: Meter GTiff UInt16
# } # Return some metadata as data.table raster_metadata(examplenames, c("res", "size", "bbox", "outformat"))
#> path #> 1: /home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/tif/L7_ETMs.tif #> 2: /home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/nc/bcsd_obs_1999.nc #> 3: /home/lranghetti/share/git/github/ranghetti/sen2r/inst/extdata/out/S2A2A_20170703_022_Barbellino_BOA_10.tif #> valid res.x res.y size.x size.y xmin ymin xmax ymax #> 1: TRUE 28.500 28.500 349 352 288776.3 9110729 298722.750 9120760.750 #> 2: TRUE 0.125 0.125 81 33 -85.0 33 -74.875 37.125 #> 3: TRUE 10.000 10.000 24 42 580560.0 5101700 580800.000 5102120.000 #> outformat #> 1: GTiff #> 2: netCDF #> 3: GTiff
# Return some metadata as list raster_metadata(examplenames, c("res", "size", "bbox", "proj"), format = "list")
#> [[1]] #> [[1]]$path #> [1] "/home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/tif/L7_ETMs.tif" #> #> [[1]]$valid #> [1] TRUE #> #> [[1]]$res #> x y #> 28.5 28.5 #> #> [[1]]$size #> x y #> 349 352 #> #> [[1]]$bbox #> xmin ymin xmax ymax #> 288776.3 9110728.8 298722.8 9120760.8 #> #> [[1]]$proj #> Coordinate Reference System: #> No EPSG code #> proj4string: "+proj=utm +zone=25 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" #> #> #> [[2]] #> [[2]]$path #> [1] "/home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/nc/bcsd_obs_1999.nc" #> #> [[2]]$valid #> [1] TRUE #> #> [[2]]$res #> x y #> 0.125 0.125 #> #> [[2]]$size #> x y #> 81 33 #> #> [[2]]$bbox #> xmin ymin xmax ymax #> -85.000 33.000 -74.875 37.125 #> #> [[2]]$proj #> Coordinate Reference System: NA #> #> #> [[3]] #> [[3]]$path #> [1] "/home/lranghetti/share/git/github/ranghetti/sen2r/inst/extdata/out/S2A2A_20170703_022_Barbellino_BOA_10.tif" #> #> [[3]]$valid #> [1] TRUE #> #> [[3]]$res #> x y #> 10 10 #> #> [[3]]$size #> x y #> 24 42 #> #> [[3]]$bbox #> xmin ymin xmax ymax #> 580560 5101700 580800 5102120 #> #> [[3]]$proj #> Coordinate Reference System: #> EPSG: 32632 #> proj4string: "+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs" #> #>
# Output with an invalid raster examplenames <- c( examplenames, system.file("extdata/settings/gdal_formats.json", package="sen2r") ) raster_metadata(examplenames, c("bbox", "proj"))
#> trying to read file: /home/lranghetti/share/git/github/ranghetti/sen2r/inst/extdata/settings/gdal_formats.json
#> path #> 1: /home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/tif/L7_ETMs.tif #> 2: /home/lranghetti/R/x86_64-pc-linux-gnu-library/3.6/stars/nc/bcsd_obs_1999.nc #> 3: /home/lranghetti/share/git/github/ranghetti/sen2r/inst/extdata/out/S2A2A_20170703_022_Barbellino_BOA_10.tif #> 4: /home/lranghetti/share/git/github/ranghetti/sen2r/inst/extdata/settings/gdal_formats.json #> valid xmin ymin xmax ymax #> 1: TRUE 288776.3 9110729 298722.750 9120760.750 #> 2: TRUE -85.0 33 -74.875 37.125 #> 3: TRUE 580560.0 5101700 580800.000 5102120.000 #> 4: FALSE NA NA NA NA #> proj #> 1: +proj=utm +zone=25 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs #> 2: <NA> #> 3: +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs #> 4: <NA>