ebv_read_bb {ebvcube}R Documentation

Read subset (bounding box) of one datacube of an EBV netCDF

Description

Read a subset of one or more layers from one datacube of the NetCDF file. Subset definition by a bounding box.

Usage

ebv_read_bb(
  filepath,
  datacubepath,
  entity = NULL,
  timestep = 1,
  bb,
  outputpath = NULL,
  epsg = 4326,
  overwrite = FALSE,
  ignore_RAM = FALSE,
  verbose = TRUE
)

Arguments

filepath

Character. Path to the netCDF file.

datacubepath

Character. Path to the datacube (use ebv_datacubepaths()).

entity

Character or Integer. Default is NULL. If the structure is 3D, the entity argument is set to NULL. Else, a character string or single integer value must indicate the entity of the 4D structure of the EBV netCDFs.

timestep

Integer. Choose one or several timesteps.

bb

Integer Vector. Definition of subset by bounding box: c(xmin, xmax, ymin, ymax).

outputpath

Character. Default: NULL, returns the data as a SpatRaster object in memory. Optional: set path to write subset as GeoTiff on disk.

epsg

Integer. Default: 4326 (WGS84). Change accordingly if your bounding box coordinates are based on a different coordinate reference system.

overwrite

Logical. Default: FALSE. Set to TRUE to overwrite the outputfile defined by 'outputpath'.

ignore_RAM

Logical. Default: FALSE. Checks if there is enough space in your memory to read the data. Can be switched off (set to TRUE).

verbose

Logical. Default: TRUE. Turn off additional prints by setting it to FALSE.

Value

Returns a SpatRaster object if no outputpath is given. Otherwise the subset is written onto the disk and the outputpath is returned.

Note

In case the epsg of the Bounding Box and the netCDF differ, the data is returned based on the epsg of the netCDF Dataset.

See Also

ebv_read_shp() for subsetting via shapefile.

Examples

#set path to EBV netCDF
file <- system.file(file.path("extdata","martins_comcom_subset.nc"), package="ebvcube")
#get all datacubepaths of EBV netCDF
datacubes <- ebv_datacubepaths(file, verbose=FALSE)

#set outputpath
out <- file.path(system.file(package='ebvcube'),"extdata","subset_bb.tif")
#define two different bounding boxes based on different EPSG codes
bb_wgs84 <- c(-26, 64, 30, 38)
bb_utm32 <- c(-2383703, 5532302, 3643854, 4564646)


## Not run: 
#read bb (based on EPSG 4326) - return SpatRaster
cSAR_subset <- ebv_read_bb(filepath = file, datacubepath = datacubes[1,1],
                             entity = 1, timestep = 1:3, bb = bb_wgs84)

#read bb (based on EPSG 4326) - write to GeoTiff
path <- ebv_read_bb(filepath = file, datacubepath = datacubes[1,1],
                    entity = 1, timestep = 1, bb = bb_wgs84,
                    outputpath = out, overwrite = TRUE)

#read bb (based on ESRI 54009) - write to GeoTiff
path  <- ebv_read_bb(filepath = file, datacubepath = datacubes[1,1],
                     entity = 1, timestep = 1:2, bb = bb_utm32,
                     epsg = 32632, outputpath = out, overwrite = TRUE)

## End(Not run)

[Package ebvcube version 0.1.7 Index]