asgrid: Convert to and from grid objects.

View source: R/asgrid.R

asgrid and rast()R Documentation

Convert to and from grid objects.

Description

Make grids from objects of type: matrix and SpatRaster (defined interra).

Usage

asgrid(x, ...)   # generic
## S3 method for class 'matrix'
asgrid(x, xll, yll, cellsize, ...)
## S3 method for class 'SpatRaster'
asgrid(x, ...)
## S4 method for signature 'grid'
rast(x)

Arguments

x

an object of class matrix, SpatRaster or grid

xll, yll

the x and y coordinates of the lower left corner of the lower left cell of the grid.

cellsize

the cellsize of the grid

...

Arguments to be passed to other methods.

Value

For asgrid an object of class grid which is a list containing the following elements.

m

a matrix containing the data from data.col. Rows progress from north to south and columns from east to west.

nrow, ncol

the number of rows and column in m.

xll, yll

the x an y coordinates of the lower left corner of the lower left cell in the matrix.

cellsize

the horizontal and vertical dimension of cells in the grid; cells must be square.

For rast a SpatRaster.

Author(s)

Ethan Plunkett

See Also

Input classes of x are defined in rast

Examples

# Matrix method
mat <- matrix(1:20, 4, 5)
g <- asgrid(mat, cellsize=10, xll=0, yll=0)
g


# To and from SpatRaster (terra::rast())
library(terra)
r <- rast(g)
g2 <- asgrid(r)


ethanplunkett/gridprocess documentation built on Feb. 1, 2024, 2:24 a.m.