This function is called by users to calculate a spectral index and extract zonal statistics for a sf object containing POLYGONS or MULTIPOLYGONS. Any ZM dimensions of the sf object are dropped before calculation. Users can specify the timeframe of the calculation as "seasonal". In this way, the calculation for each year specified in the years variables is done separately. This allows users to only cover specific timeframes within several years. If timeframe is "complete" it is assumed that the complete timeseries of the input files should be covered by the temporal resolution specified in the dt variable.

index_cube(
  files = NULL,
  format = system.file("sentinel2_l2a_cog.json", package = "mapme.vegetation"),
  DB_path = NULL,
  dx = NULL,
  dy = NULL,
  dt = NULL,
  srs = NULL,
  bbox = NULL,
  after = NULL,
  before = NULL,
  timeframe = "full",
  aggregation = "median",
  resampling = "bilinear",
  tmpagg = FALSE,
  index = NULL,
  bands = NULL,
  label = "",
  outdir = ".",
  overwrite = F,
  mask_layer = NULL,
  mask_values = NULL,
  mask_invert = FALSE,
  chunking = c(1, 256, 256),
  threads = 1,
  ...
)

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

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.

timeframe

A character of either "seasonal" or "complete" specifying if the calculation should be applied for the complete time series or for each year independently. Defaults to "complete". If "seasonal" is specified the years variables cannot be left empty.

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".

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 ".".

overwrite

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

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.

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

...

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

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