Learn R Programming

raster (version 3.6-30)

Raster-class: Raster* classes

Description

A raster is a database organized as a rectangular grid that is sub-divided into rectangular cells of equal area (in terms of the units of the coordinate reference system). The 'raster' package defines a number of "S4 classes" to manipulate such data.

The main user level classes are RasterLayer, RasterStack and RasterBrick. They all inherit from BasicRaster and can contain values for the raster cells.

An object of the RasterLayer class refers to a single layer (variable) of raster data. The object can point to a file on disk that holds the values of the raster cells, or hold these values in memory. Or it can not have any associated values at all.

A RasterStack represents a collection of RasterLayer objects with the same extent and resolution. Organizing RasterLayer objects in a RasterStack can be practical when dealing with multiple layers; for example to summarize their values (see calc) or in spatial modeling (see predict).

An object of class RasterBrick can also contain multiple layers of raster data, but they are more tightly related. An object of class RasterBrick can refer to only a single (multi-layer) data file, whereas each layer in a RasterStack can refer to another file (or another band in a multi-band file). This has implications for processing speed and flexibility. A RasterBrick should process quicker than a RasterStack (irrespective if values are on disk or in memory). However, a RasterStack is more flexible as a single object can refer to layers that have values stored on disk as well as in memory. If a layer that does not refer to values on disk (they only exists in memory) is added to a RasterBrick, it needs to load all its values into memory (and this may not be possible because of memory size limitations).

Objects can be created from file or from each other with the following functions: raster, brick and stack.

Raster* objects can also be created from SpatialPixels* and SpatialGrid* objects from the sp package using as, or simply with the function raster, brick, or stack. Vice versa, Raster* objects can be coerced into a sp type object with as( , ), e.g. as(x, 'SpatialGridDataFrame') .

Common generic methods implemented for these classes include:

summary, show, dim, and plot, ...

[ is implemented for RasterLayer.

The classes described above inherit from the BasicRaster class which inherits from BasicRaster. The BasicRaster class describes the main properties of a raster such as the number of columns and rows, and it contains an object of the link[raster]{Extent-class} to describe its spatial extent (coordinates). It also holds the 'coordinate reference system' in a slot of class CRS-class defined in the sp package. A BasicRaster cannot contain any raster cell values and is therefore seldomly used.

The Raster* class inherits from BasicRaster. It is a virtual class; which means that you cannot create an object of this class. It is used only to define methods for all the classes that inherit from it (RasterLayer, RasterStack and RasterBrick). Another virtual class is the RasterStackBrick class. It is formed by a class union of RasterStack and RasterBrick. You cannot make objects of it, but methods defined for objects of this class as arguments will accept objects of the RasterLayer and RasterStack as that argument.

Classes RasterLayer and RasterBrick have a slot with an object of class RasterFile that describes the properties of the file they point to (if they do). RasterLayer has a slot with an object of class SingleLayerData, and the RasterBrick class has a slot with an object of class MultipleLayerData. These 'datalayer' classes can contain (some of) the values of the raster cells.

These classes are not further described here because users should not need to directly access these slots. The 'setter' functions such as setValues should be used instead. Using such 'setter' functions is much safer because a change in one slot should often affect the values in other slots.

Arguments

Objects from the Class

Objects can be created by calls of the form new("RasterLayer", ...), or with the helper functions such as raster.

Slots

Slots for RasterLayer and RasterBrick objects

title:

Character

file:

Object of class ".RasterFile"

data:

Object of class ".SingleLayerData" or ".MultipleLayerData"

history:

To record processing history, not yet in use

legend:

Object of class .RasterLegend, Default legend. Should store preferences for plotting. Not yet implemented except that it stores the color table of images, if available

extent:

Object of Extent-class

ncols:

Integer

nrows:

Integer

crs:

Object of class "CRS", i.e. the coordinate reference system. In Spatial* objects this slot is called 'proj4string'

Examples

Run this code
showClass("RasterLayer")

Run the code above in your browser using DataLab