| 1 |
\name{as.SpatialPolygons.GridTopology} |
| 2 |
\alias{as.SpatialPolygons.GridTopology} |
| 3 |
\alias{coerce,GridTopology,SpatialPolygons-method} |
| 4 |
\alias{HexPoints2SpatialPolygons} |
| 5 |
\alias{IDvaluesGridTopology} |
| 6 |
\alias{as.SpatialPolygons.SpatialPixels} |
| 7 |
\alias{coerce,SpatialPixels,SpatialPolygons-method} |
| 8 |
\alias{IDvaluesSpatialPixels} |
| 9 |
%- Also NEED an '\alias' for EACH other topic documented here. |
| 10 |
\title{Make SpatialPolygons object from GridTopology object} |
| 11 |
\description{ |
| 12 |
Converts grids of regular rectangles into a \code{SpatialPolygons} object, which can be transformed to a different projection or datum with \code{spTransform} in package \code{rgdal}. The function is not suitable for high-resolution grids. The ordering of the grid cells is as in \code{coordinates()} of the same object, and is reported by \code{IDvaluesGridTopology}. |
| 13 |
} |
| 14 |
\usage{ |
| 15 |
as.SpatialPolygons.GridTopology(grd, proj4string = CRS(as.character(NA))) |
| 16 |
IDvaluesGridTopology(obj) |
| 17 |
as.SpatialPolygons.SpatialPixels(obj) |
| 18 |
IDvaluesSpatialPixels(obj) |
| 19 |
HexPoints2SpatialPolygons(hex, dx) |
| 20 |
} |
| 21 |
%- maybe also 'usage' for other objects documented here. |
| 22 |
\arguments{ |
| 23 |
\item{grd}{\code{GridTopology} object} |
| 24 |
\item{proj4string}{object of class \link{CRS-class}} |
| 25 |
\item{obj}{ \code{SpatialPixels} object } |
| 26 |
\item{hex}{ \code{SpatialPoints} object with points that are generated by hexagonal sampling; |
| 27 |
see \link{spsample}} |
| 28 |
\item{dx}{ spacing of two horizontally adjacent points; if missing, this will be computed |
| 29 |
from the points } |
| 30 |
} |
| 31 |
|
| 32 |
\value{ |
| 33 |
\code{as.SpatialPolygons.GridTopology} and \code{as.SpatialPolygons.SpatialPixels} return a \code{SpatialPolygons} object; |
| 34 |
\code{IDvaluesGridTopology} and \code{IDvaluesSpatialPixels} return a character vector with the object grid indices. |
| 35 |
} |
| 36 |
|
| 37 |
\seealso{\code{\link{GridTopology}}, \code{\link{SpatialPixels}}, \code{\link{SpatialPolygons}} |
| 38 |
\code{spTransform} in package \code{rgdal} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
\examples{ |
| 43 |
library(lattice) |
| 44 |
grd <- GridTopology(cellcentre.offset=c(-175,55), cellsize=c(10,10), cells.dim=c(4,4)) |
| 45 |
SpP_grd <- as.SpatialPolygons.GridTopology(grd) |
| 46 |
plot(SpP_grd) |
| 47 |
text(coordinates(SpP_grd), sapply(slot(SpP_grd, "polygons"), function(i) slot(i, "ID")), cex=0.5) |
| 48 |
trdata <- data.frame(A=rep(c(1,2,3,4), 4), B=rep(c(1,2,3,4), each=4), |
| 49 |
row.names=sapply(slot(SpP_grd, "polygons"), function(i) slot(i, "ID"))) |
| 50 |
SpPDF <- SpatialPolygonsDataFrame(SpP_grd, trdata) |
| 51 |
spplot(SpPDF) |
| 52 |
|
| 53 |
data(meuse.grid) |
| 54 |
gridded(meuse.grid)=~x+y |
| 55 |
xx = spsample(meuse.grid, type="hexagonal", cellsize=200) |
| 56 |
xxpl = HexPoints2SpatialPolygons(xx) |
| 57 |
image(meuse.grid["dist"]) |
| 58 |
plot(xxpl, add = TRUE) |
| 59 |
points(xx, cex = .5) |
| 60 |
\dontrun{ |
| 61 |
spplot(aggregate(as(meuse.grid[,1:3], "SpatialPolygonsDataFrame"), xxpl, |
| 62 |
areaWeighted=TRUE), main = "aggregated meuse.grid") |
| 63 |
} |
| 64 |
} |
| 65 |
\keyword{spatial} |