Learn R Programming

terra (version 1.7-55)

dimensions: Dimensions of a SpatRaster or SpatVector and related objects

Description

Get the number of rows (nrow), columns (ncol), cells (ncell), layers (nlyr), sources (nsrc), the size size (nlyr(x)*ncell(x)), or spatial resolution of a SpatRaster.

length returns the number of sub-datasets in a SpatRasterDataset or SpatVectorCollection.

For a SpatVector length(x) is the same as nrow(x).

You can also set the number of rows or columns or layers. When setting dimensions, all cell 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 nsrc(x)

# S4 method for SpatRaster,numeric ncol(x)<-value

# S4 method for SpatRaster,numeric nrow(x)<-value

# S4 method for SpatRaster,numeric nlyr(x)<-value

# S4 method for SpatRaster res(x)

# S4 method for SpatRaster,numeric 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 length(x)

Value

integer

Arguments

x

SpatRaster or SpatVector or related objects

value

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

See Also

ext

Examples

Run this code
r <- rast()
ncol(r)
nrow(r)
nlyr(r)
dim(r)
nsrc(r)
ncell(r)

rr  <- c(r,r)
nlyr(rr)
nsrc(rr)
ncell(rr)

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 DataLab