View source: R/functions_netCDF.R
get_xyspace | R Documentation |
Extract xy-space values
get_xyspace(
x,
crs,
res,
xy_names = c("lon", "lat"),
tol = sqrt(.Machine[["double.eps"]])
)
x |
An object that describes a gridded or discrete xy-space. Regular, rectangular grids are the only currently supported grid. This can be
|
crs |
An object which is a crs or from which one can be derived.
|
res |
A numeric vector of length two. The (absolute values of) cell size/resolution/delta of the x and y dimensions in units of the crs. |
xy_names |
A vector with two character strings. The names of the x and y spatial dimensions of a netCDF file. |
tol |
A numeric value. The tolerance applied to determine if a grid is regular and to calculate grid resolution. |
A list with three elements: two vectors one each containing all unique values of the x coordinate and the y coordinates of (i) all gricell centers, if gridded, or (ii) all sites, if discrete; and a vector res with the (regular) x and y resolutions, if gridded (NA, if discrete).
The argument crs
is only used if grid
is a data.frame
,
in which case it is passed to as_points
.
Otherwise, it is ignored and can be missing.
The argument res
is only used in two cases:
if grid
is a list,
such as the one produced by get_xyspace
, but does
not contain a named element res; or
if grid
is an object with coordinate values for
all gridcell centers.
Otherwise, it is ignored and can be missing.
# grid as terra object
r <- terra::rast(
xmin = 0, xmax = 120,
ymin = 0, ymax = 45,
crs = "OGC:CRS84",
resolution = c(1, 1)
)
get_xyspace(r)
# grid as data frame with coordinate values
rdf <- terra::crds(r)
get_xyspace(rdf, crs = "OGC:CRS84", res = c(1, 1))
# a list with vectors for all x values and all y values (and resolution)
rl <- list(
x = sort(unique(rdf[, 1])),
y = sort(unique(rdf[, 2]))
)
get_xyspace(c(rl, list(res = c(1, 1))))
get_xyspace(rl, res = c(1, 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.