thanks
Horacio
On Feb 1, 2006, at 12:54 PM, Edzer J. Pebesma wrote:
A Horacio Samaniego wrote:
I wonder how I should go from a SpatialGrid to a
SpatialGridDataFrame.
Using for example the function SpatialGridDataFrame()
I have defined a grid using the functions from the sp, gstat and
spgrass6 packages:
G<-gmeta6()
kk<-SpatialGrid(GridTopology(c(G$south,G$west),c(G$nsres,G
$ewres),c (G$rows,G$cols)),alb.proj)
Formal class 'SpatialGrid' [package "sp"] with 5 slots
..@ grid :Formal class 'GridTopology' [package "sp"] with
3 slots
.. .. ..@ cellcentre.offset: num [1:2] -1333373 -2356259
.. .. ..@ cellsize : num [1:2] 1000 1000
.. .. ..@ cells.dim : int [1:2] 2899 4615
..@ grid.index : int(0)
..@ coords : num [1:2, 1:2] -1333373 1564162 -2356259 2257928
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
..@ bbox : num [1:2, 1:2] -1333872 -2356759 1564662 2258428
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr "+proj=aea +lat_1=29.75 +lat_2=45.25
+lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +no_defs +a=6378137
+rf=298.257222101 +towgs84=0.000,0"| __truncated__
Now I try to interpolate on that grid, with no success:
interp.vals<-idw(var1~1,data,newdata=kk)
Error in idw(corrext ~ 1, data = data.new_alb[gd.glm, ], newdata
= data.grd) :
no direct or inherited method for function 'idw' for this call
So, I guess that I need to have a 'SpatialGridDataFrame' instead
of just 'SpatialGrid' as the interpolation needs to be assigned
to a spatial location
newdata can be of class SpatialGrid; probably idw fails because
of the data argument. What is the class of data.new_alb[gd.glm,] ?
kk2<-as(kk,'SpatialGridDataFrame');
Formal class 'SpatialGridDataFrame' [package "sp"] with 6 slots
..@ data :Formal class 'AttributeList' [package "sp"]
with 1 slots
.. .. ..@ att: list()
..@ grid :Formal class 'GridTopology' [package "sp"] with
3 slots
.. .. ..@ cellcentre.offset: num [1:2] -1333373 -2356259
.. .. ..@ cellsize : num [1:2] 1000 1000
.. .. ..@ cells.dim : int [1:2] 2899 4615
..@ grid.index : int(0)
..@ coords : num [1:2, 1:2] -1333373 1564162 -2356259 2257928
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
..@ bbox : num [1:2, 1:2] -1333872 -2356759 1564662 2258428
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr "+proj=aea +lat_1=29.75 +lat_2=45.25
+lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +no_defs +a=6378137
+rf=298.257222101 +towgs84=0.000,0"| __truncated__
promotes the grid to the correct class SpatialGridDataFrame but
do not assign to space for the variable. Is there any way to
assign an empty "slot" just as we would do for a data.frame?
To sum. I cant seem to be able to create a "slot" (or z
dimension) to hold the output of my interpolation. Is there any
trick out there that I am missing? Any help will be appreciated.
thanks,
H