[R-sig-Geo] Coerce list to SpatialGridDataFrame?
Roger Bivand
Roger.Bivand at nhh.no
Fri Aug 4 11:24:37 CEST 2006
On Fri, 4 Aug 2006, Michael Sumner wrote:
> A correction (due to grid orientation), with example:
>
> library(rgdal)
> d <- list(x =1:10, y = 2:11, z = matrix(1:100, 10, 10))
> gt <- GridTopology(cellcentre.offset = c(d$x[1], d$x[2]),
> cellsize = c(diff(d$x[1:2])/2, diff(d$y[1:2])/2), cells.dim = dim(d$z))
>
> ## because of the way the grids are oriented compared to the normal R image
> grd.atts <- SpatialGridDataFrame(gt, list(depth =
> as.vector(d$z[,ncol(d$z):1])))
Almost. The image() function is a bit wierd, so you do need to be careful.
A couple of small suggestions:
d <- list(x =1:10, y = 22:31, z = matrix(1:100, 10, 10))
image(d)
gt <- GridTopology(cellcentre.offset = c(d$x[1], d$y[1]),
cellsize = c(diff(d$x[1:2]), diff(d$y[1:2])), cells.dim = dim(d$z))
grd.atts <- SpatialGridDataFrame(gt, list(depth =
as.vector(d$z[,ncol(d$z):1])))
image(grd.atts, axes=TRUE)
gets the cell centres and sizes right (assuming x and y are
centre-registered).
Roger
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list