[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 16:16:35 CEST 2013


Edzer,

Aargh! A stupid mistake on my part. Indeed, in the past I had also loaded maptools, I did it now and indeed the conversion works.

I was misled by the thought that the type conversion would be by the packages that defined of the class(es) in question, in this case sp and spatstat. Of course there is no reason why another package can not read both those classes and do the conversion.

Again, apologies for cluttering the list, but maybe someone searching the archives will have made a similar oversight.


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


> 
> ------------------------------
> 
> Message: 15
> Date: Tue, 18 Jun 2013 08:47:04 +0200
> From: Edzer Pebesma <edzer.pebesma at uni-muenster.de>
> To: r-sig-geo at r-project.org
> Subject: Re: [R-sig-Geo] Broken conversion from sp to spatstat ppp
> Message-ID: <51C00268.4020208 at uni-muenster.de>
> Content-Type: text/plain; charset=windows-1252
> 
> David, iirc these conversion methods are in package maptools.
> 
> On 06/18/2013 08:40 AM, d.g.rossiter at utwente.nl wrote:
>> 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)
>> 
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> 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
> 83 33081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
> 



More information about the R-sig-Geo mailing list