I´m trying to follow the tutorial "Handling shape files in the spatstat package" by Adrian Baddeley where a shape as SpatialPolygonsDataFrame is converted to a collection of owin´s.
The key attributes of shape are summarized below and my objective is to test whether a collection of points are within a collection of polygons.
summary(shape)
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
x -43.13679 -42.95351
y -22.98961 -22.85380
Is projected: FALSE
proj4string : [+proj=longlat +ellps=GRS80 +no_defs]
it has 907 polygons here are the suggested transformations
cp <- as(shape, "SpatialPolygons")
cregions <- slot(cp, "polygons")
cregions <- lapply(cregions, function(x) { SpatialPolygons(list(x)) })
cwindows <- lapply(cregions, as.owin)
but I get the error
Error in as.owin.default(X[[1L]], ...) : Can't interpret W as a window
Any ideas? Thanks