[R-sig-Geo] Broken conversion from sp to spatstat ppp

d.g.rossiter at utwente.nl d.g.rossiter at utwente.nl
Tue Jun 18 08:40:17 CEST 2013


Since upgrading to R 3.0.1 and the latest version of packages sp 1.0.9, gstat 1.0.16, spatstat 1.31-13 the following conversion no longer works:

> require(gstat)
> data(meuse)
> coordinates(meuse) <- ~x + y
> meuse.ppp <- as(meuse, "ppp")

Error message:

Error in as(ds, "ppp") : 
  no method or default for coercing "SpatialPointsDataFrame" to "ppp"

Trying another way:

…
> meuse.ppp <- as.ppp(meuse)

Gives a different error message:

Error in as.ppp.default(ds) : Can't interpret X as a point pattern

But I suppose these are at root the same problem.

I can get around this with:

> x <- coordinates(meuse)[,1]
> y <- coordinates(meuse)[,2]
> l1 <- bbox(meuse)[1,1]
> l2 <- bbox(meuse)[1,2]
> l3 <- bbox(meuse)[2,1]
> l4 <- bbox(meuse)[2,2]
> win <- owin(xrange=c(l1,l2), yrange=c(l3,l4))
> class(win)
[1] "owin"
> win
window: rectangle = [178605, 181390] x [329714, 333611] units  
> meuse.ppp <- ppp(x, y, window=win, marks=meuse at data)
> plot(meuse.ppp, which.marks="ffreq")

So it seems the conversion routine should be easy to implement or adjust to whatever has changed in R 3.0.

D G Rossiter
Senior University Lecturer
Faculty of Geoinformation and Earth   Observation Science
Universiteit Twente.
Enschede (NL)



More information about the R-sig-Geo mailing list