[R-sig-Geo] krige does not accept SpatialPixels objects

Edzer J. Pebesma e.pebesma at geo.uu.nl
Sun Jan 29 20:49:17 CET 2006


Patrick Giraudoux wrote:

> Dear Edzer,
>
> I am revisiting/training with gstat using the tutorial (vignette) and 
> applying it to an example of Cs distribution in Franche-Comté. Looks 
> like if a small bug was in krige().
>
> If you make a grid just with coordinates, eg:
>
> Csnewsp.grid<-expand.grid(x=seq(bbox(Csnewsp)[1,1],bbox(Csnewsp)[1,2],by=4500),y=seq(bbox(Csnewsp)[2,1],bbox(Csnewsp)[2,2],by=4500))
> coordinates(Csnewsp.grid)<-~x+y
> gridded(Csnewsp.grid)<-TRUE
>
> a call to
>
> cs2002.idw<-krige(CD2002~1,Csnewsp,Csnewsp.grid)
>
> gives:
>
> > cs2002.idw<-krige(CD2002~1,Csnewsp,Csnewsp.grid)
> Error in as.data.frame.default(newdata) : cannot coerce class 
> "SpatialPixels" into a data.frame
>
> However, if you add a variable like that:
>
> Csnewsp.grid<-expand.grid(x=seq(bbox(Csnewsp)[1,1],bbox(Csnewsp)[1,2],by=4500),y=seq(bbox(Csnewsp)[2,1],bbox(Csnewsp)[2,2],by=4500))
> Csnewsp.grid<-cbind(Csnewsp.grid,fact=1) # add a non sense variable
> coordinates(Csnewsp.grid)<-~x+y
> gridded(Csnewsp.grid)<-TRUE
>
> Everything looks OK:
>
> > cs2002.idw<-krige(CD2002~1,Csnewsp,Csnewsp.grid)
> [inverse distance weighted interpolation]
>
> Suppose the trouble comes when a SpatialPixel object is given as a 
> grid when a SpatialPixelDataFrame is expected... This may happen when 
> the grid is just the coordinates and does not include other variables, 
> which may be often the case.
>
> Is it normal or is there a mistake on my side?
>
> All the best,
>
> Patrick
>
Patrick, this is not a mistake on your side; objects of class
SpatialPixels (or SpatialGrid) were lacking an as.data.frame()
method. They have one now; I added this to package sp (on which
gstat now depends), it is in sp version 0.8-9 which should
be available from CRAN within a few days.

Thanks,
--
Edzer




More information about the R-sig-Geo mailing list