terra (version 0.3-7)

dimensions: Dimensions of a SpatRaster or SpatVector

Description

Get the number of rows (nrow), columns (ncol), cells (ncell), layers (nlyr), sources (nsrc) or the spatial resolution of a SpatRaster. Set the number of rows or columns or layers. When setting dimensions, all sources and values are dropped.

Usage

# S4 method for SpatRaster
ncol(x)
# S4 method for SpatRaster
nrow(x)
# S4 method for SpatRaster
nlyr(x)
# S4 method for SpatRaster
ncell(x)
# S4 method for SpatRaster
size(x)
# S4 method for SpatRaster
nsrc(x)
# S4 method for SpatRaster
res(x)

ncol(x, ...) <- value nrow(x, ...) <- value nlyr(x, ...) <- value res(x) <- value

# S4 method for SpatRaster xres(x) # S4 method for SpatRaster yres(x)

# S4 method for SpatVector ncol(x) # S4 method for SpatVector nrow(x) # S4 method for SpatVector size(x, ...) # S4 method for SpatVector length(x)

Arguments

x

SpatRaster or SpatVector

value

For ncol and nrow: positive integer. For res: one or two positive numbers

...

additional arguments. None implemented

Value

integer

See Also

ext

Examples

Run this code
# NOT RUN {
r <- rast()
ncell(r)
ncol(r)
nrow(r)
dim(r)
nsrc(r)

nrow(r) <- 18
ncol(r) <- 36
# equivalent to
dim(r) <- c(18, 36) 

dim(r)
dim(r) <- c(10, 10, 5)
dim(r)

xres(r)
yres(r)
res(r)

#res(r) <- 1/120
# different xres and yres
#res(r) <- c(1/120, 1/60)
# }

Run the code above in your browser using DataCamp Workspace