Message-ID: <SNT117-W262E934DEB092BD2DB290AC5780@phx.gbl>
Date: 2011-05-29T17:22:17Z
From: Chris English
Subject: Creating SpatialGridDataFrame - unequal number of objects
In-Reply-To: <911240847.1117036.1306625949474.JavaMail.root@zmail.uaex.edu>
Re: [R-sig-Geo] R spatial matrix to SpatialGridDataFrameEdzer Pebesma
Tue, 26 Jan 2010 00:54:21 -0800?suggested the following to?Ian McCallum - herein adapted
?bike_1<- list(x = 1:1824, y = 1:1824, z = matrix(rep(1824:1, each=1824), ncol=1824, byrow=TRUE))
> bgrid<- GridTopology(cellcentre.offset = c(bike_1$x[1], bike_1$y[1]), cellsize =?+ c(bike_1$x[1], bike_1$y[1]), cells.dim = dim(bike_1$z))
> bike_1_sgdf<- SpatialGridDataFrame(bgrid, data.frame(depth =?+ as.vector(bike_1$z[,ncol(bike_1$z):1])))
> image(bike_1_sgdf, axes = TRUE)
This produces the highly desired and previously elusive SGDF. I would neverhave figured out the "data.frame(depth = & etc" myself and have plenty of examples ofSGDF's that contain none of the values I sought to show for my efforts.
This approach requires x=z and so my prior z=y is untenable. When viewed in imagethe values seem rotated clockwise 90 deg, which I guess is just matrix vs raster origin.?
I was hoping to?attain a grid of x= 1824, y= 1368, and z values descending?from 1368:1 by column. ?And thence create a Terragen file through rgdal.
I suppose I can rotate, clip & etc post rgdal but wonder if I can simplify my approach.
Thanks,Chris
----------------------------------------
> From: tgriffin at uaex.edu
> Subject: RE: [R-sig-Geo] Creating SpatialGridDataFrame - unequal number of objects
> Date: Sat, 28 May 2011 18:39:09 -0500
> To: sglish at hotmail.com; r-sig-geo at r-project.org
>
>
>
> Terry Griffin, PhD
> tgriffin at uaex.edu
> 501.249.6360
>
> -----Original Message-----
> From: Chris English
> Sent: Saturday, May 28, 2011 11:20 AM
> To: r-sig-geo at r-project.org
> Subject: [R-sig-Geo] Creating SpatialGridDataFrame - unequal number of objects
>
>
> Dear List:
> I have a SpatialGrid for which I am trying to make adata.frame and thence a SpatialGridDataFrame.
> I can't seem to get the size of data.frame and gridto match up. I assume I'm missing something straight forward.
>
> summary(grid1)Object of class SpatialGridCoordinates: min maxx 0.5 1824.5y 0.5 1368.5Is projected: NA proj4string : [NA]Number of points: 2Grid attributes: cellcentre.offset cellsize cells.dimx 1 1 1824y 1 1 1368> help(str)> bike_mat<- matrix(rep(1368:1, each=1824), ncol=1824, byrow=TRUE)> bike_df<- as.data.frame(bike_mat)> bike_sgdf_1<- SpatialGridDataFrame(grid1,bike_df)Error in validityMethod(object) : unequal number of objects in full grid and data slot
> Thank you for you assistance.
> Chris
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo