[R-sig-Geo] help using irregular polygons R with spatstat package

Adrian Baddeley adrian at maths.uwa.edu.au
Mon Oct 19 09:22:32 CEST 2009


Raya A. Pruner <rpruner at ufl.edu>  writes:

> I have loaded the following libraries in R: sp, rgdal, spatstat, 
> and maptools. 

> I've used essentially the following code (substituting my actual 
> files):

> boundary=readOGR(dsn="polygon.shp",layer= "polygon")
> nests=readOGR(dsn="nest.location.shp", layer="nest.location")
> boundary.owin=as(as(boundary,"SpatialPolygons"),"owin")
> nests.points=as(nests,"SpatialPoints")
> nests.ppp=as.ppp(nests.points,W=boundary.owin)

> All script works fine except for the last line.  When I run this 
> one, I get the following error:

> Error in as.ppp.SpatialPoints(nest.points, W = boundary.owin) :
>  unused argument(s) (W = list(type = "polygonal", xrange = 
> c(252580.626188745,.........

> Does anyone know what this error message means?  And suggestions 
> on what I can/should do????

This means that 'W' was not a recognised argument of 'as.ppp.SpatialPoints'. 

When you tried to convert the object 'nests.points' (of class "SpatialPoints") 
to the class "ppp" using the generic command 'as.ppp', the method 'as.ppp.SpatialPoints'
from the library 'maptools' was invoked. This function (which you can inspect by typing
its name) has only one argument, X. There is currently no facility to specify the window
by a second argument W.

The easiest way to get what you want is to use the 'ppp' command in spatstat.

nests.ppp <- ppp(nests.points[,1], nests.points[,2], window=boundary.owin)

Alternatively you could use the following modified version of 'as.ppp.SpatialPoints' 
which does behave as you wanted.

as.ppp.SpatialPoints <- function (X, W=NULL)
{
    require(spatstat)
    bb <- bbox(X)
    colnames(bb) <- NULL
    if(is.null(W)) W = owin(bb[1, ], bb[2, ])
    cc = coordinates(X)
    return(ppp(cc[, 1], cc[, 2], window = W, marks = NULL, check = FALSE))
}


regards
Adrian Baddeley



More information about the R-sig-Geo mailing list