grd | R Documentation |
grd()
objects are just an array (any object with more than
two dim()
s) and a bounding box (a rct()
, which may or
may not have a wk_crs()
attached). The ordering of the dimensions
is y (indices increasing downwards), x (indices increasing to the right).
This follows the ordering of as.raster()
/rasterImage()
and aligns
with the printing of matrices.
grd(
bbox = NULL,
nx = NULL,
ny = NULL,
dx = NULL,
dy = NULL,
type = c("polygons", "corners", "centers")
)
grd_rct(data, bbox = rct(0, 0, dim(data)[2], dim(data)[1]))
grd_xy(data, bbox = rct(0, 0, dim(data)[2] - 1, dim(data)[1] - 1))
as_grd_rct(x, ...)
## S3 method for class 'wk_grd_rct'
as_grd_rct(x, ...)
## S3 method for class 'wk_grd_xy'
as_grd_rct(x, ...)
as_grd_xy(x, ...)
## S3 method for class 'wk_grd_xy'
as_grd_xy(x, ...)
## S3 method for class 'wk_grd_rct'
as_grd_xy(x, ...)
bbox |
A |
nx , ny , dx , dy |
Either a number of cells in the x- and y- directions
or delta in the x- and y-directions (in which case |
type |
Use "polygons" to return a grid whose objects can be
represented using an |
data |
An object with two or more dimensions. Most usefully, a matrix. |
x |
An object to convert to a grid |
... |
Passed to S3 methods |
grd()
returns a grd_rct()
for type == "polygons
or
a grd_xy()
otherwise.
grd_rct()
returns an object of class "wk_grd_rct".
grd_xy()
returns an object of class "wk_grd_xy".
# create a grid with no data (just for coordinates)
(grid <- grd(nx = 2, ny = 2))
as_rct(grid)
as_xy(grid)
plot(grid, border = "black")
# more usefully, wraps a matrix or nd array + bbox
# approx volcano in New Zealand Transverse Mercator
bbox <- rct(
5917000, 1757000 + 870,
5917000 + 610, 1757000,
crs = "EPSG:2193"
)
(grid <- grd_rct(volcano, bbox))
# these come with a reasonable default plot method for matrix data
plot(grid)
# you can set the data or the bounding box after creation
grid$bbox <- rct(0, 0, 1, 1)
# subset by indices or rct
plot(grid[1:2, 1:2])
plot(grid[c(start = NA, stop = NA, step = 2), c(start = NA, stop = NA, step = 2)])
plot(grid[rct(0, 0, 0.5, 0.5)])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.