classRaster_as.matrix: Convert raster image to a matrix

as.matrixR Documentation

Convert raster image to a matrix

Description

as.matrix(coords=TRUE) prepares a list from the first band of ursaRaster, which is suitable as input parameter for functions image, contour and filled.contour.

Usage

## S3 method for class 'ursaRaster'
as.matrix(x, ...)
## S3 method for class 'ursaRaster'
x[[i]]

Arguments

x

Object of class ursaRaster

...

Set of arguments, which are recognized via their names (using regular expressions) and classes.

(coord(s)*|crd|^$)

Logical If TRUE then list is created with x, y, z components, where component $z contains matrix, components $x and $y are coordinates for elements if matrix.

i

Positive integer or character of lentg. If integer, then band index. If character, then band name. If missing, then first band (value 1L) is used.

Details

Item colortable is mainly for internal usage, e. g., for mapping. Item proj is useful for convertion back to ursaRaster object by calling as.ursa function.

Extract operator x[[i]] is a wrapper for as.matrix(x[i],coords=TRUE)

Value

Depending of argument coords.

If coords=FALSE, then it is a two-dimensional matrix c(samples*lines, bands), unclassed from ursaValue class.

If coords=TRUE, then it is a list:

x

Numeric. Midpoints of cells on horizontal axis

y

Numeric. Midpoints of cells on vertical axis

z

Numeric. Matrix of values

attr(*,"proj")

PROJ.4 string for grid, defined by x and y

attr(*,"colortable")

Optional. Object of class ursaColorTable. Missing if raster has no color table.

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

session_grid(NULL)
a <- ursa_dummy(nband=3,min=0,max=100)
a <- a[a>=20 & a<=80]
ignorevalue(a) <- 121
str(ursa_value(a[2]))
str(as.matrix(a[2]))
b1 <- a[[2]]
str(b1)
image(b1,asp=1)
b2 <- as.matrix(a[2:3],coords=TRUE)
print(c('theSame?'=identical(b1,b2)))
a2 <- as.ursa(b2)
res <- c(src=a[2],exported_then_imported=a2,diff=a[2]-a2)
print(res)

ursa documentation built on March 18, 2022, 6:23 p.m.