[R-sig-Geo] R spatial matrix to SpatialGridDataFrame
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Tue Jan 26 09:53:44 CET 2010
Something seems to have changed, since 2006 ... The following should work:
library(sp)
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, data.frame(depth =
as.vector(d$z[,ncol(d$z):1])))
image(grd.atts, axes=TRUE)
Ian McCallum wrote:
> Greetings,
>
> I am trying to export a matrix out to an arcinfo asciigrid.
> Write tables might work.
> Better is perhaps write.asciigrid or writeGDAL
> To do that however, i need to convert my matrix into a Spatial Grid.
>
> I came across a thread (from R. Bivand in 2006) that seems to address
> what i need to do.
> However if i plug this into R, it fails. I run R 2.10.1 on win XP.
> Any ideas on why this is crashing, and how to export a matrix to
> arcinfo asciigrid would be great.
>
> Thanks
> Ian
>
>
> > library(sp)
> > 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])))
> Error in validObject(.Object) :
> invalid class "SpatialGridDataFrame" object: invalid object for
> slot "data" in class "SpatialGridDataFrame": got class "list", should
> be or extend class "data.frame"
> > image(grd.atts, axes=TRUE)
> Error in image(grd.atts, axes = TRUE) : object 'grd.atts' not found
>
>
>
>
>
>
> ___________________________________________
> Ian McCallum
> Forestry Program
> International Institute for Applied Systems Analysis
> Schlossplatz 1, A-2361 Laxenburg, Austria
> Phone: +43 2236 807-328
> Fax: +43 2236 807-599 or 71313
> E-mail: mccallum at iiasa.ac.at
> Web: http://www.iiasa.ac.at/Research/FOR/
> ___________________________________________
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics e.pebesma at wwu.de
More information about the R-sig-Geo
mailing list