File: as.SpatialPolygons.GridTopology.Rd

package info (click to toggle)
r-cran-sp 1:0.9-66-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,696 kB
  • ctags: 123
  • sloc: ansic: 1,475; sh: 6; makefile: 5
file content (63 lines) | stat: -rw-r--r-- 2,720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
\name{as.SpatialPolygons.GridTopology}
\alias{as.SpatialPolygons.GridTopology}
\alias{coerce,GridTopology,SpatialPolygons-method}
\alias{HexPoints2SpatialPolygons}
\alias{IDvaluesGridTopology}
\alias{as.SpatialPolygons.SpatialPixels}
\alias{coerce,SpatialPixels,SpatialPolygons-method}
\alias{IDvaluesSpatialPixels}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{Make SpatialPolygons object from GridTopology object}
\description{
  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}.
}
\usage{
as.SpatialPolygons.GridTopology(grd, proj4string = CRS(as.character(NA)))
IDvaluesGridTopology(obj)
as.SpatialPolygons.SpatialPixels(obj)
IDvaluesSpatialPixels(obj)
HexPoints2SpatialPolygons(hex, dx)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{grd}{\code{GridTopology} object}
  \item{proj4string}{object of class \link{CRS-class}}
  \item{obj}{ \code{SpatialPixels} object }
  \item{hex}{ \code{SpatialPoints} object with points that are generated by hexagonal sampling; 
  see \link{spsample}}
  \item{dx}{ spacing of two horizontally adjacent points; if missing, this will be computed
  from the points }
}

\value{
  \code{as.SpatialPolygons.GridTopology} and \code{as.SpatialPolygons.SpatialPixels} return a \code{SpatialPolygons} object;
\code{IDvaluesGridTopology} and \code{IDvaluesSpatialPixels} return a character vector with the object grid indices.
}

\seealso{\code{\link{GridTopology}}, \code{\link{SpatialPixels}}, \code{\link{SpatialPolygons}}
\code{spTransform} in package \code{rgdal}
}


\examples{
library(lattice)
grd <- GridTopology(cellcentre.offset=c(-175,55), cellsize=c(10,10), cells.dim=c(4,4))
SpP_grd <- as.SpatialPolygons.GridTopology(grd)
plot(SpP_grd)
text(coordinates(SpP_grd), sapply(slot(SpP_grd, "polygons"), function(i) slot(i, "ID")), cex=0.5)
trdata <- data.frame(A=rep(c(1,2,3,4), 4), B=rep(c(1,2,3,4), each=4), row.names=sapply(slot(SpP_grd, "polygons"), function(i) slot(i, "ID")))
SpPDF <- SpatialPolygonsDataFrame(SpP_grd, trdata)
spplot(SpPDF)

data(meuse.grid)
gridded(meuse.grid)=~x+y
xx = spsample(meuse.grid,  type="hexagonal", cellsize=200)
xxpl = HexPoints2SpatialPolygons(xx)
image(meuse.grid["dist"])
plot(xxpl, add = TRUE)
points(xx, cex = .5)
df = as.data.frame(meuse.grid)[overlay(meuse.grid, xx),]
x = SpatialPolygonsDataFrame(xxpl, df, match.ID = FALSE)
spplot(x, "dist")
}
\keyword{spatial}