dataFromGrid: Extract data from a gridded dataset

View source: R/dataFromGrid.R

dataFromGridR Documentation

Extract data from a gridded dataset

Description

This function extracts data from a gridded dataset based on given coordinates.

Usage

dataFromGrid(grid, varname, lon, lat, times = FALSE)

Arguments

grid

a RasterBrick or RasterStack object or a path to a NetCDF file.

varname

a character string specifying the name of the variable to extract in NetCDF file.

lon

numeric vector with longitude(s) of target location(s).

lat

numeric vector with latitude(s) of target location(s).

times

logical. If TRUE, time dimension will be extracted from data and the returned values will be in form of a zoo object. Only works for NetCDF and RasterBrick.

Details

The argument time searches the time dimension and its units in the gridded dataset (NetCDF or RasterBrick). If it can't be found, only the data will be returned.

Arguments lon and lat define the coordinates that must be in the same projection as the gridded dataset. If there is no spatial coincidence, returned object will be empty.

Value

A matrix with same columns as pairs of coordinates defined in lon and lat arguments. If times is TRUE, the matrix will be a zoo object.

Examples



try(
 dataFromGrid(grid = "tmax.nc",
                 varname = 'tn',
                 lon = c(41.39, 42),
                 lat = c(2.17, 2.5),
                 times = FALSE)
)


agroclim documentation built on Oct. 14, 2022, 9:05 a.m.