Skip to content
Prev 6673 / 29559 Next

help using irregular polygons R with spatstat package

On Mon, 19 Oct 2009, Adrian Baddeley wrote:

            
Yes, this is the easiest. But you can also say:

nests.ppp <- as(nests.points, "ppp")
nests.ppp$window <- boundary.owin

This will not check the window for appropriateness. The function
as.ppp.SpatialPoints() is user-visible as an S3 method, but is really an 
S4 coercion method, which does not admit extra arguments. The sp classes 
are S4, while spatstat classes are S3. The following:

window.ppp <- function(x, ...) {
   stopifnot(inherits(x, "ppp"))
   x$window
}

"window<-.ppp" <- function(x, ..., value) {
   stopifnot(inherits(x, "ppp"))
   stopifnot(inherits(value, "owin"))
   x$window <- value
}

use the generics defined in the stats package, and the replacement method 
could be extended to include checking from the ppp() function to make sure 
that the new window is appropriate.

Then the inadequate:

nests.ppp$window <- boundary.owin

could become:

window(nests.ppp) <- boundary.owin

Best wishes,

Roger