I. Creating Raster* objects
Raster* objects can be created, from scracth or from raster files, with the following functions:
ll{
raster To create a RasterLayer
stack To create a RasterStack (multiple layers)
brick To create a RasterBrick (multiple layers)
addLayer Add a layer to a RasterStack or RasterBrick
dropLayer Remove a layer from a RasterStack or RasterBrick
unstack Create a list of RasterLayer objects from a RasterStack
}
RasterLayer, RasterStack, and RasterBrick objects are, as a group, referred to as Raster* objectsII. Changing the spatial extent and/or resolution of Raster* objects
ll{
merge Combine Raster* objects with different extents (but same origin and resolution)
mosaic Combine RasterLayer objects with different extents; using a function to set values for overlapping areas
crop Select a geographic subset of a Raster* object
expand Enlarge a Raster* object
trim Trim a Raster* object by removing exterior rows and/or columns that only have NA values
aggregate Combine cells of a Raster* object to create larger cells
disaggregate Subdivide cells
shift Move the location of Raster
flip Flip values horizontally or vertically
rotate Rotate values (for lon/lat data)
resample Warp values to a Raster* object with a different origin or resolution
projectRaster Warp values to a Raster* object with a different coordinate reference system
}III. Raster algebra
ll{
Arith-methods Arith functions (+, -, *, ^, %%, %/%, /)
Math-methods Math functions (abs, sqrt, trunc, log, log10, exp, cos, sin, gamma, round among others)
Logic-methods Logic functions (!, &, |)
Summary-methods Summary functions (mean, Median, max, min, range, prod, sum, any, all)
Compare-methods Compare functions (==, !=, >, <, <=",">=,>)
}IV. Cell based computation
ll{
calc Computations on a single Raster* object
stackApply Computations on groups of layers in Raster* object
overlay Computations on multiple RasterLayer objects
cover First layer covers second layer except where the first layer is NA
mask Use values from first Raster except where cells of the mask Raster are NA (these become NA)
reclass Reclassify using a 'from-to-becomes' matrix
subs Substitute values using a 'is-becomes' matrix
init Initialize cells with new values
}V. Spatial contextual computation
ll{
distance Shortest distance to a cell that is not NA
gridDistance Distance when traversing grid cells that are not NA
distanceFromPoints Shortest distance to any point in a set of points
direction Direction (azimuth) to or from cells that are not NA
focal Focal (neighborhood) functions
focalFilter Focal (neighborhood) filters
edge Edge detection
clump Find clumps (patches)
adjacency Identify cells that are adjacent to a set of cells on a raster
area Compute area of cells (for longitude/latitude data)
}VI. Model predictions
ll{
predict Predict a non-spatial model to a RasterLayer
interpolate Predict a spatial model to a RasterLayer
}VIII. Summarizing
ll{
cellStats Summarize a Raster cell values with a function
summary Summary of the values of a Raster* object (quartiles and mean)
freq Frequency table of Raster cell values
count Count the frequency of a single (range of) value(s)
crosstab Cross-tabulate two RasterLayer objects
unique Get the unique values in a RasterLayer
zonal Summarize a RasterLayer by zones in another RasterLayer
}IX. Accessing values of Raster* object cells
ll{
getValues Get all cell values (will fail with very large rasters and limited computer memory), or a row of values (safer)
getValuesBlock Get values for a block (a rectangular area defined by start and end row and column
xyValues Use points (optionally with a buffer) to extract cell values
cellValues Use cell numbers to extract cell values
polygonValues Use a SpatialPolygons* object to extract cell values
focalValues Extract values from focal cells
sampleRandom Random sample
sampleRegular Regular sample
minValue The minimum value of the cells of a Raster* object (not always known)
maxValue The maximum value of the cells of a Raster* object (not always known)
setMinMax Compute the minimum and maximum value of a Raster* object if these are not known
}
You can also use indexing with [ for cell numbers, and [[ for row / column number combinationsX. Plotting
Maps
ll{
plot Plot a Raster* object. The main method to create a map
plotRGB Combine three layers (red, green, blue channels) into a single 'real color' image
plot3D 3-dimensional plot of a RasterLayer
image Plot a Raster* using the image function
persp Perspective plot of a RasterLayer
contour Contour plot of a RasterLayer
filledContour Filled contour plot of a RasterLayer
text Plot the values of a RasterLayer on top of a map
}
Interacting with a map (plot of a RasterLayer)
ll{
zoom Zoom in on a plot of a RasterLayer
click Draw points and/or query values of RasterLayer by clicking on a map
drawPoly Create a SpatialPolygons object by drawing it
drawLine Create a SpatialLines object by drawing it
drawExtent Create an Extent object by drawing it
}
Other plots
ll{
plot x-y plot of values of two RasterLayer objects
hist Histogram of Raster* object values
density Density plot of Raster* object values
pairs Pairs plot for layers in a RasterStack or RasterBrick
}XI. Getting and setting Raster* dimensions
Basic parameters of existing Raster* objects can be obtained, and in most cases changed, with:
ll{
ncol The number of columns
nrow The number of rows
ncell The number of cells (can not be set directly, only via ncol or nrow)
res The resolution (x and y)
xres The x resolution (can be set with res)
yres The y resolution (can be set with res)
xmin The minimum x coordinate (or longitude)
xmax The maximum x coordinate (or longitude)
ymin The minimum y coordinate (or latitute)
ymax The maximum y coordinate (or latitute)
extent The extent (minimum and maximum x and y coordinates)
origin The origin of a Raster* object
projection The coordinate reference system (map projection)
isLonLat Test if an object has a longitude/latitude coordinate reference system
filename Filename to which RasterLayer or RasterBrick is linked
band Band (layer) of a multi-band file that this RasterLayer is linked to
nbands How many bands (layers) does the file have?
compare Compare the basic parameters of two Raster* objects
NAvalue Get or set the NA value (for reading from file)
}
If there are values associated with a RasterLayer object (either in memory or via a link to a file) these are lost when you change the number of columns or rows or the resolution. This is not the case when the extent is changed (as the number of columns and rows will not be affected). Simlarly, with projection you can set the projection, but this does not transform the data (see projectRaster for that).XII. Computing row, column, cell numbers and coordinates
Cell numbers start at 1 in the upper-left corner. They increase within rows, from left to right, and then row by row from top to bottom. Likewise, row numbers start at 1 at the top of the raster, and column numbrers start at 1 at the left side of the raster.
ll{
xFromCol x-coordinates from column numbers
yFromRow y-coordinates from row numbers
xFromCell x-coordinates from row numbers
yFromCell y-coordinates from cell numbers
xyFromCell x and y coordinates from cell numbers
colFromX Column numbers from x-coordinates (or longitute)
rowFromY Row numbers from y-coordinates (or latitute)
cellFromXY Cell numbers from x and y coordinates
cellFromRowCol Cell numbers from row and column numbers
cellsFromExtent Cell numbers from extent object
validCell Is this a valid cell number?
validCol Is this a valid column number?
validRow Is this a valid row number?
}XIII. Writing files
Basic writing
ll{
setValues Put new values in a Raster* object
writeRaster Write all values of Raster* object to disk
KML Save raster as KML file
}
Advanced writing of entire files or parts thereof
ll{
blockSize Get suggested block size for reading and writing
writeStart Open a file for writing
writeValues Write some values
writeStop Close the file after writing
}XIV. Extent objects
ll{
extent Create an extent object
intersectExtent Intersect two extent objects
unionExtent Combine two extent objects
alignExtent Align an extent with a Raster* object
roundExtent Round the coordinates of an Extent object
nudgeExtent Floor/ceiling of the coordinates of an Extent object
drawExtent Create an Extent object by drawing it on top of a map (see plot)
polygonFromExtent Create a SpatialPolygons object from an Extent object
}
It is also possible to use Arithmetic functions with Extent objects (but these work perhaps unexpectedly!)Acknowledgements
We thank the following persons for suggestions to improve the package:
Roger Bivand, Jonathan Greenberg, Herry Herry, Paul Hiemstra, Mayeul Kauffmann, Rainer Krug, Alice Laborte, John Lewis, Lennon Li, Agustin Lobo,
Matteo Mattiuzzi, Steven Mosher, Edzer Pebesma, Jon Olav Skoien, and Kevin Ummel.