| 1 |
\name{image.SpatialGridDataFrame} |
| 2 |
\alias{image.SpatialGridDataFrame} |
| 3 |
\alias{image.SpatialPixelsDataFrame} |
| 4 |
\alias{image.SpatialPixels} |
| 5 |
\alias{contour.SpatialGridDataFrame} |
| 6 |
\alias{contour.SpatialPixelsDataFrame} |
| 7 |
\alias{as.image.SpatialGridDataFrame} |
| 8 |
\alias{image2Grid} |
| 9 |
\alias{imageScale} |
| 10 |
\title{ Image or contour method for gridded spatial data; convert to and from image data structure } |
| 11 |
\description{ Create image for gridded data in SpatialGridDataFrame or SpatialPixelsDataFrame |
| 12 |
objects. } |
| 13 |
\usage{ |
| 14 |
\method{image}{SpatialGridDataFrame}(x, attr = 1, xcol = 1, ycol = 2, |
| 15 |
col = heat.colors(12), red=NULL, green=NULL, blue=NULL, |
| 16 |
axes = FALSE, xlim = NULL, |
| 17 |
ylim = NULL, add = FALSE, ..., asp = NA, setParUsrBB=FALSE, |
| 18 |
interpolate = FALSE, angle = 0, |
| 19 |
useRasterImage = !(.Platform$GUI[1] == "Rgui" && |
| 20 |
getIdentification() == "R Console") && missing(breaks), breaks, |
| 21 |
zlim = range(as.numeric(x[[attr]])[is.finite(x[[attr]])])) |
| 22 |
\method{image}{SpatialPixelsDataFrame}(x, ...) |
| 23 |
\method{image}{SpatialPixels}(x, ...) |
| 24 |
\method{contour}{SpatialGridDataFrame}(x, attr = 1, xcol = 1, ycol = 2, |
| 25 |
col = 1, add = FALSE, xlim = NULL, ylim = NULL, axes = FALSE, |
| 26 |
..., setParUsrBB = FALSE) |
| 27 |
\method{contour}{SpatialPixelsDataFrame}(x, ...) |
| 28 |
as.image.SpatialGridDataFrame(x, xcol = 1, ycol = 2, attr = 1) |
| 29 |
image2Grid(im, p4 = as.character(NA), digits=10) |
| 30 |
} |
| 31 |
\arguments{ |
| 32 |
\item{x}{ object of class \link{SpatialGridDataFrame} } |
| 33 |
\item{attr}{ column of attribute variable; this may be |
| 34 |
the column name in the data.frame of \code{data} (as.data.frame(data)), or |
| 35 |
a column number } |
| 36 |
\item{xcol}{ column number of x-coordinate, in the coordinate matrix } |
| 37 |
\item{ycol}{ column number of y-coordinate, in the coordinate matrix } |
| 38 |
\item{col}{a vector of colors } |
| 39 |
\item{red,green,blue}{columns names or numbers given instead of the \code{attr} argument when the data represent an image encoded in three colour bands on the 0-255 integer scale; all three columns must be given in this case, and the attribute values will be constructed using function \code{rgb} } |
| 40 |
%\item{asp}{ aspect ratio of unit x and unit y axis } |
| 41 |
\item{axes}{ logical; should coordinate axes be drawn? } |
| 42 |
\item{xlim}{ x-axis limits } |
| 43 |
\item{ylim}{ y-axis limits } |
| 44 |
\item{zlim}{ data limits for plotting the (raster, attribute) values } |
| 45 |
\item{add}{ logical; if FALSE, the image is added to the plot layout setup |
| 46 |
by \code{plot(as(x, "Spatial"),axes=axes,xlim=xlim,ylim=ylim,asp=asp)} |
| 47 |
which sets up axes and plotting region; if TRUE, the image is added |
| 48 |
to the existing plot. } |
| 49 |
\item{...}{ arguments passed to \link{image}, see examples } |
| 50 |
\item{asp}{ aspect ratio to be used for plot } |
| 51 |
\item{setParUsrBB}{default FALSE, see \code{\link{Spatial-class}} for further details} |
| 52 |
\item{useRasterImage}{if TRUE, use \code{\link[graphics]{rasterImage}} to render the image if available; for legacy rendering set FALSE; should be FALSE on Windows SDI installations} |
| 53 |
\item{breaks}{class breaks for coloured values} |
| 54 |
\item{interpolate}{default FALSE, a logical vector (or scalar) indicating whether to apply linear interpolation to the image when drawing, see \code{\link[graphics]{rasterImage}}} |
| 55 |
\item{angle}{default 0, angle of rotation (in degrees, anti-clockwise from positive x-axis, about the bottom-left corner), see \code{\link[graphics]{rasterImage}}} |
| 56 |
\item{im}{list with components named x, y, and z, as used for \code{image}} |
| 57 |
\item{p4}{CRS object, proj4 string} |
| 58 |
\item{digits}{default 10, number of significant digits to use for checking equal row/column spacing} |
| 59 |
} |
| 60 |
\value{ \code{as.image.SpatialGridDataFrame} returns the list with |
| 61 |
elements \code{x} and \code{y}, containing the coordinates of the cell |
| 62 |
centres of a matrix \code{z}, containing the attribute values in matrix |
| 63 |
form as needed by \link{image}. } |
| 64 |
|
| 65 |
\note{ Providing \code{xcol} and \code{ycol} attributes seems obsolete, |
| 66 |
and it is for 2D data, but it may provide opportunities for plotting |
| 67 |
certain slices in 3D data. I haven't given this much thought yet. |
| 68 |
|
| 69 |
\link{filled.contour} seems to misinterpret the coordinate values, |
| 70 |
if we take the image.default manual page as the reference. } |
| 71 |
|
| 72 |
|
| 73 |
\author{ Edzer Pebesma } |
| 74 |
|
| 75 |
\seealso{ \link{image.default}, \link{SpatialGridDataFrame-class}, |
| 76 |
\link[lattice]{levelplot} in package \code{lattice}. Function |
| 77 |
\code{image.plot} in package \code{fields} can be used to make a legend for an |
| 78 |
image, see an example in \url{https://stat.ethz.ch/pipermail/r-sig-geo/2007-June/002143.html} |
| 79 |
} |
| 80 |
|
| 81 |
\examples{ |
| 82 |
data(meuse.grid) |
| 83 |
coordinates(meuse.grid) = c("x", "y") # promote to SpatialPointsDataFrame |
| 84 |
gridded(meuse.grid) = TRUE # promote to SpatialGridDataFrame |
| 85 |
data(meuse) |
| 86 |
coordinates(meuse) = c("x", "y") |
| 87 |
image(meuse.grid["dist"], main = "Distance to river Meuse") |
| 88 |
points(coordinates(meuse), pch = "+") |
| 89 |
image(meuse.grid["dist"], main = "Distance to river Meuse", |
| 90 |
useRasterImage=TRUE) |
| 91 |
points(coordinates(meuse), pch = "+") |
| 92 |
|
| 93 |
# color scale: |
| 94 |
layout(cbind(1,2), c(4,1),1) |
| 95 |
image(meuse.grid["dist"]) |
| 96 |
imageScale(meuse.grid$dist, axis.pos=4, add.axis=FALSE) |
| 97 |
axis(4,at=c(0,.2,.4,.8), las=2) |
| 98 |
|
| 99 |
data(Rlogo) |
| 100 |
d = dim(Rlogo) |
| 101 |
cellsize = abs(c(gt[2],gt[6])) |
| 102 |
cells.dim = c(d[1], d[2]) # c(d[2],d[1]) |
| 103 |
cellcentre.offset = c(x = gt[1] + 0.5 * cellsize[1], y = gt[4] - (d[2] - 0.5) * abs(cellsize[2])) |
| 104 |
grid = GridTopology(cellcentre.offset, cellsize, cells.dim) |
| 105 |
df = as.vector(Rlogo[,,1]) |
| 106 |
for (band in 2:d[3]) df = cbind(df, as.vector(Rlogo[,,band])) |
| 107 |
df = as.data.frame(df) |
| 108 |
names(df) = paste("band", 1:d[3], sep="") |
| 109 |
Rlogo <- SpatialGridDataFrame(grid = grid, data = df) |
| 110 |
summary(Rlogo) |
| 111 |
image(Rlogo, red="band1", green="band2", blue="band3") |
| 112 |
image(Rlogo, red="band1", green="band2", blue="band3", |
| 113 |
useRasterImage=FALSE) |
| 114 |
is.na(Rlogo$band1) <- Rlogo$band1 == 255 |
| 115 |
is.na(Rlogo$band2) <- Rlogo$band2 == 255 |
| 116 |
is.na(Rlogo$band3) <- Rlogo$band3 == 255 |
| 117 |
Rlogo$i7 <- 7 |
| 118 |
image(Rlogo, "i7") |
| 119 |
image(Rlogo, red="band1", green="band2", blue="band3", add=TRUE) |
| 120 |
} |
| 121 |
|
| 122 |
\keyword{spatial} |