| 1 |
\name{SpatialGridDataFrame-class} |
| 2 |
\docType{class} |
| 3 |
\alias{SpatialGridDataFrame-class} |
| 4 |
\alias{[,SpatialGridDataFrame-method} |
| 5 |
\alias{show,SpatialGridDataFrame-method} |
| 6 |
\alias{cbind.SpatialGridDataFrame} |
| 7 |
% \alias{SpatialGridDataFrame} |
| 8 |
\alias{plot.SpatialGridDataFrame} |
| 9 |
\alias{print.summary.SpatialGridDataFrame} |
| 10 |
\alias{as.array.SpatialGridDataFrame} |
| 11 |
\alias{coerce,SpatialGridDataFrame,SpatialPointsDataFrame-method} |
| 12 |
\alias{coerce,SpatialGridDataFrame,SpatialPixelsDataFrame-method} |
| 13 |
\alias{coerce,SpatialGridDataFrame,SpatialPolygonsDataFrame-method} |
| 14 |
\alias{coerce,SpatialGridDataFrame,data.frame-method} |
| 15 |
\alias{coerce,SpatialGridDataFrame,matrix-method} |
| 16 |
\alias{coerce,SpatialGridDataFrame,array-method} |
| 17 |
\alias{as.data.frame.SpatialGridDataFrame} |
| 18 |
\alias{dim.SpatialGridDataFrame} |
| 19 |
\alias{coerce,im,SpatialGridDataFrame-method} |
| 20 |
\alias{coerce,ppp,SpatialGridDataFrame-method} |
| 21 |
\alias{plot,SpatialGridDataFrame,missing-method} |
| 22 |
|
| 23 |
\title{Class "SpatialGridDataFrame" } |
| 24 |
\description{ Class for spatial attributes that have spatial locations |
| 25 |
on a (full) regular grid. } |
| 26 |
\section{Objects from the Class}{ |
| 27 |
Objects can be created by calls of the form \code{as(x, |
| 28 |
"SpatialGridDataFrame")}, where \code{x} is of class |
| 29 |
\link{SpatialPixelsDataFrame-class}, or by importing through rgdal. |
| 30 |
Ordered full grids are stored instead or unordered non-NA cells; |
| 31 |
} |
| 32 |
|
| 33 |
\section{Slots}{ |
| 34 |
\describe{ |
| 35 |
\item{\code{grid}:}{see \link{GridTopology-class}; grid parameters } |
| 36 |
\item{\code{bbox}:}{Object of class \code{"matrix"}; bounding box } |
| 37 |
\item{\code{proj4string}:}{Object of class \code{"CRS"}; projection } |
| 38 |
\item{\code{data}:}{Object of class data.frame, containing attribute data } |
| 39 |
} |
| 40 |
} |
| 41 |
\section{Extends}{ |
| 42 |
Class \code{"SpatialGrid"}, directly. |
| 43 |
Class \code{"Spatial"}, by class \code{"SpatialGrid"}. |
| 44 |
} |
| 45 |
\section{Methods}{ |
| 46 |
\describe{ |
| 47 |
\item{coordinates}{\code{signature(x = "SpatialGridDataFrame")}: retrieves (and calculates!) coordinates } |
| 48 |
\item{[}{\code{signature(x = "SpatialGridDataFrame")}: selects rows, columns, and attributes; returns an |
| 49 |
object of class \code{SpatialGridDataFrame}} |
| 50 |
\item{as.matrix}{\code{signature(x = "SpatialGridDataFrame")}: coerce to matrix; increasing col index corresponds to decreasing y coordinate, row index increases with coordinate index } |
| 51 |
\item{as.array}{\code{signature(x = "SpatialGridDataFrame")}: coerce to array; increasing array index for the second dimension corresponds to decreasing coordinates, all other coordinate dimensions increase with array index } |
| 52 |
\item{cbind}{\code{signature(...)}: if arguments have identical topology, combine their |
| 53 |
attribute values} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
\section{Plot method arguments}{ |
| 58 |
The plot methods for \dQuote{SpatialPixelsDataFrame} or \dQuote{SpatialGridDataFrame} |
| 59 |
objects take the following arguments: |
| 60 |
\describe{ |
| 61 |
\item{x}{object of class \link{SpatialPixelsDataFrame} or \link{SpatialGridDataFrame}} |
| 62 |
\item{...}{ arguments passed on to \link{image.SpatialGridDataFrame}} |
| 63 |
\item{attr}{ integer or character, indicating the attribute variable to be plotted; default 1} |
| 64 |
\item{col}{ color ramp to be used; default \code{bpy.colors(100)} for continuous, or |
| 65 |
\code{RColorBrewer::brewer.pal(nlevels(x[[1]]), "Set2")} for factor variables} |
| 66 |
\item{breaks}{ for continuous attributes: values at which color breaks should take place } |
| 67 |
\item{zlim}{ for continuous attributes: |
| 68 |
numeric of length 2, specifying the range of attribute values to be plotted; |
| 69 |
default to data range \code{range(as.numeric(x[[attr]])[is.finite(x[[attr]])])}} |
| 70 |
\item{axes}{ logical: draw x and y axes? default \code{FALSE}} |
| 71 |
\item{xaxs}{character, default "i", see \link{par}} |
| 72 |
\item{yaxs}{character, default equal to \code{xaxs}, see \link{par}} |
| 73 |
\item{at}{numeric or NULL, values at which axis tics and labels should be drawn; default NULL (use \link{pretty})} |
| 74 |
\item{border}{color, to be used for drawing grid lines; default NA (don't draw grid lines)} |
| 75 |
\item{axis.pos}{integer, 1-4; default 4, see \link{axis}} |
| 76 |
\item{add.axis}{logical: draw axis along scale? default \code{TRUE}} |
| 77 |
\item{what}{what to draw: \code{"image"}, \code{"scale"}, or \code{"both"}; default "both"} |
| 78 |
\item{scale.size}{size for the scale bar; use \link{lcm} to specify in absolute size, or a numeric |
| 79 |
value such as \code{1/6} to specify relative size; default \code{lcm(2.8)}} |
| 80 |
\item{scale.shrink}{ non-negative numeric indicating the amount to shrink the scale length, default 0} |
| 81 |
\item{scale.frac}{for categorical attributes: numeric between 0 and 1, indicating the scale width, default 0.3} |
| 82 |
\item{scale.n}{for categorical attributes: integer, indicating how many scale categories should fill a complete width; default 15} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
\author{ Edzer Pebesma, \email{[email protected]} } |
| 87 |
|
| 88 |
\seealso{ |
| 89 |
\code{\link{SpatialGrid-class}}, which does not contain the attribute data, |
| 90 |
and \code{\link{SpatialPixelsDataFrame-class} which holds possibly incomplete |
| 91 |
grids } |
| 92 |
|
| 93 |
Plotting gridded data with sp: \url{https://r-spatial.org/r/2016/03/08/plotting-spatial-grids.html} |
| 94 |
} |
| 95 |
\examples{ |
| 96 |
data(meuse.grid) # only the non-missing valued cells |
| 97 |
coordinates(meuse.grid) = c("x", "y") # promote to SpatialPointsDataFrame |
| 98 |
gridded(meuse.grid) <- TRUE # promote to SpatialPixelsDataFrame |
| 99 |
x = as(meuse.grid, "SpatialGridDataFrame") # creates the full grid |
| 100 |
x[["idist"]] = 1 - x[["dist"]] # assigns new attribute |
| 101 |
image(x["idist"]) # note the single [ for attribute selection |
| 102 |
|
| 103 |
# toy example: |
| 104 |
df = data.frame(z = c(1:6,NA,8,9), |
| 105 |
xc = c(1,1,1,2,2,2,3,3,3), |
| 106 |
yc = c(rep(c(0, 1.5, 3),3))) |
| 107 |
coordinates(df) = ~xc+yc |
| 108 |
gridded(df) = TRUE |
| 109 |
df = as(df, "SpatialGridDataFrame") # to full grid |
| 110 |
image(df["z"]) |
| 111 |
# draw labels to verify: |
| 112 |
cc = coordinates(df) |
| 113 |
z=df[["z"]] |
| 114 |
zc=as.character(z) |
| 115 |
zc[is.na(zc)]="NA" |
| 116 |
text(cc[,1],cc[,2],zc) |
| 117 |
|
| 118 |
# the following is weird, but illustrates the concept of row/col selection: |
| 119 |
fullgrid(meuse.grid) = TRUE |
| 120 |
image(meuse.grid) |
| 121 |
image(meuse.grid[20:70, 10:70, "dist"], add = TRUE, col = bpy.colors()) |
| 122 |
|
| 123 |
# as.matrix, as.array |
| 124 |
sgdim = c(3,4) |
| 125 |
SG = SpatialGrid(GridTopology(rep(0,2), rep(10,2), sgdim)) |
| 126 |
SGDF = SpatialGridDataFrame(SG, data.frame(val = 1:12)) |
| 127 |
as.array(SGDF) |
| 128 |
as.matrix(SGDF) |
| 129 |
as(SGDF, "array") |
| 130 |
} |
| 131 |
\keyword{classes} |