Learn R Programming

ursa (version 3.10.4)

as.array: Export raster object to multidimensional array

Description

In the ursaRaster object the 3-dimensional image data are presented in 2-dimensional matrix. as.array transforms internal 2-dimensional data to the usual 3-dimansional data. as.matrix just extracts image data in internal 2-dimensional format.

Usage

# S3 method for ursaRaster
as.array(x, ...)

## non-public .as.array(x, drop = FALSE, flip = FALSE, permute = FALSE, dim = FALSE)

Value

If dim=FALSE then as.array returns object of class array.

If dim=TRUE then as.array returns dimension of array.

as.matrix returns object of class matrix.

Arguments

...

Arguments, which are passed to .as.array.

x

ursaRaster object

drop

Logical. If drop=TRUE then single-band images are presented without third dimension.

permute

Logical. If permute=FALSE then returned array has dimension (samples, lines, bands). If permute=TRUE then returned array has dimension (lines, samples, bands).

flip

Logical. If flip=TRUE then vertical flip (reverse coordinates for dimension #2) is applied for output image.

dim

Logical. If dim=TRUE then array's dimension is returned.

Author

Nikita Platonov platonov@sevin.ru

Details

Use permute=TRUE to create an object of class raster: as.raster(as.array(...))

The spatial reference system is lost.

See Also

as.raster is a function to direct export to the object of class raster.
as.matrix with argument/value coords=TRUE and as.data.frame for object of class ursaRaster keep spatial reference system.

Examples

Run this code
session_grid(NULL)
a <- pixelsize()
a <- (a-global_min(a))/(global_max(a)-global_min(a))
b <- c(entire=a,half=a/2,double=a*2)
str(m <- as.matrix(b))
str(d1 <- as.array(b))
str(d2 <- as.array(b[1],drop=FALSE))
str(d3 <- as.array(b[1],drop=TRUE))
contour(d3)
filled.contour(d3)
d4 <- as.array(b,perm=TRUE)/global_max(b)
d4[is.na(d4)] <- 0
str(d4 <- as.raster(d4))
plot(d4)

Run the code above in your browser using DataLab