dot-calc_index: Calculate a spectral index with gdalcubes

.calc_indexR Documentation

Calculate a spectral index with gdalcubes

Description

This function is used internally to calculate a spectral index using the gdalcubes package. It is called by calcIndex() on a given set of SAFE directories. A user defined cube view defined by the x and y resolution, the time resolution, a CRS, as well as aggregation methods is applied. Additionally, the time dimension can be aggregated which is useful for seasonal calculations of a given index. The output of the function is a GTiff file for each time step labeled as <label>_<index>_<timestep>.tif. Zonal statistics are written to a Geopackage for each timestep labeled as <label>_<index>_<timestep>.gpkg to outdir.

Usage

.calc_index(
  files,
  format = "mapme.vegetation/inst/sentinel2_l2a_cog.json",
  DB_path = NULL,
  dx = NULL,
  dy = NULL,
  dt = NULL,
  srs = NULL,
  bbox = NULL,
  aggregation = "median",
  resampling = "bilinear",
  after = NULL,
  before = NULL,
  tmpagg = FALSE,
  index = NULL,
  bands = NULL,
  label = NULL,
  outdir = ".",
  mask_layer = "SCL",
  mask_values = c(3, 8, 9),
  mask_invert = FALSE,
  overwrite = F,
  chunking = c(1, 256, 256),
  threads = 1,
  verbose = TRUE,
  ...
)

Arguments

files

A character vector with the filepaths to the raster files for which gap-filling and a smoothing function shall be applied.

format

A charachter vector pointing to a json file with a gdalcubes format description of the input files.

DB_path

A charachter vector where the gdalcubes data base file indexing the spatiotemporal extents of files. Defaults to NULL which means a temporary file is used. Can be pointed to a file ending in ".db" to speed up later iterations.

dx

A numeric specifying the resolution of the output raster in x dimension expressed in the map unit specified in epsg. If epsg is left empty it defaults to the map unit of aoi.

dy

A numeric specifying the resolution of the output raster in y dimension expressed in the map unit specified in epsg. If epsg is left empty it defaults to the map unit of aoi.

dt

Resolution of the time dimension expressed as ISO8601 string (e.g. "P16D" for 16 days).

srs

Target spatial reference system as a string; can be a proj4 definition, WKT, or in the form "EPSG:XXXX" (see cube_view)

bbox

A numeric vector of lenght four indicating the spatial bounding box of the query (xmin, ymin, xmax, ymax) in geographic coordinates. Defaults to 'NULL' which will set the spatial extent to global, i.e. c(-180, -90, 180, 90).

aggregation

A character vector specifying the aggregation method for images of the same time stamp. Must be one of "min", "max", "mean", "median", or "first". Defaults to "median".

resampling

A character specifying the resampling method used to transform images from their native CRS to the output CRS. Can be any of the methods supported by gdalwarp (see www.gdal.org/programs/gdalwarp.html). Defaults to "bilinear".

after

A length one character vector in the form ' the earliest date (inclusive) included in the temporal extent.

before

A length one character vector in the form ' the latest date (inclusive) included in the temporal extent.

tmpagg

A logical indicating if temporal aggregation of all timestemps should be performed calling reduce_time. Defaults to FALSE.

index

A character specifying the short name of the index to be calculated. Available indices can be checked with check_indices(). Defaults to NULL. When indices are calculated argument bands must be set to NULL.

bands

A character vector specifying the bands to extract. Defaults to NULL. If specified argument index must be set to NULL.

label

A character label which is appended to the output files in the form of <label>_<index>_<timestep>. Files with the same name in outdir will be overwritten without warning.

outdir

A character specifying an existing directory where output files will be written to. Defaults to ".".

mask_layer

Name of a layer in the data cube used for masking.

mask_values

An integer vector with mask values. Masking behaviour is controlled with the mask_invert argument.

mask_invert

If TRUE the values specified in mask_values are considered valid and pixels with these values are kept. If FALSE pixel with these values are masked out. Default is FALSE.

overwrite

A logical indicating if existing files in outdir should be overwritten.

chunking

Vector of length 3 defining the size of data cube chunks in the order time, y, x. (see raster_cube)

threads

Number of cores used for parallel processing

verbose

A logical indicating the verbosity.

...

additional arguments to write_tif

Value

Nothing. However a GTiff and a GPKG with the zonal statistics are written to outdir for every resulting timestep.

Note

See cube_view for more information.

Author(s)

Darius Görgen (MapTailor Geospatial Consulting GbR) info@maptailor.net
Maintainer: MAPME-Initiative contact@mapme-initiative.org
Contact Person: Dr. Johannes Schielein
Copyright: MAPME-Initiative
License: GPL-3


mapme-initiative/mapme.vegetation documentation built on Feb. 10, 2023, 10:51 p.m.