as.raster
Manipulate raster objects
Description
Creates or manages raster objects, which are matrices of
colors in row-major order.
Usage
as.raster(x, ...)
## S3 method for class 'numeric':
as.raster(x, max = 1, ...)
## S3 method for class 'character':
as.raster(x, max = 1, ...)
## S3 method for class 'logical':
as.raster(x, max = 1, ...)
## S3 method for class 'matrix':
as.raster(x, max = 1, ...)
## S3 method for class 'array':
as.raster(x, max = 1, ...)
## S3 method for class 'raster':
as.raster(x, ...)
is.raster(x)
## S3 method for class 'raster':
print(x, ...)
## S3 method for class 'raster':
x[i, j, drop, ...]
## S3 method for class 'raster':
x[i, j] <- value
Arguments
x |
For as.raster, an object to convert into a raster object.
as.raster is a generic function. Methods in the grDevices
package can manage numeric, character, and logical vectors and matrices,
and three dimensional numeric arrays with 3 or 4 slabs. Other packages
can define methods for more classes.
For is.raster, any object.
For the others, an object of class "raster".
|
max |
Passed to rgb as its maxColorValue argument when it is converting
numeric or logical color values to color strings. The values in x
should be between 0 and max, inclusive.
|
... |
For the numeric, character, and logical methods of as.raster, these
are passed to matrix. They should be the number of rows and columns
in the raster object.
|
Details
A raster object is a matrix of color strings of the form "#RRGGBB" or #RRGGBBAA"
where "RR", "GG", and "BB" are two hexadecimal digits representing the intensity
of the red, green, and blue components of the color on a scale of 0x00 to 0xFF
(0-255 decimal), and "AA" is an optional pair of hexadecimal digits giving the
opacity of the color. (If "AA" is omitted, it is taken to be "FF", making the
color comletely opaque.) The matrix of colors is stored in row major order,
which is convenient for processing images by other software.
- as.raster.array can take either an nrow-by-ncol-by-3 or an nrow-by-ncol-by-4
array of numbers. The first three slabs specify the red, green, and blue
components of the color, and the optional fourth slab specifies the opacity.
- as.raster.matrix, as.raster.numeric, and as.raster.logical
produce colors with identical red, green, and blue values (hence grayscale values).
- The vector methods as.raster.numeric, as.raster.logical, and as.raster.character
let you supply the nrow and ncol arguments to matrix so you
can specify the shape of your raster object.
- as.raster.character does not check that its input consists of valid
color strings.
Subscripting a raster object always produces a raster object. You are
warned if you try to use
drop=TRUE when subscripting.
Note
Because TERR has no graphics system, there is no plot method for raster objects.
See Also
rbg.
Examples
as.raster(matrix(1:6, 2, 3), max=8)
as.raster(array(1:24, c(2,3,4)), max=32)
as.raster(matrix(c("red","green","blue","black","white","yellow"), nrow=2))