Marco Helbich <marco.helb...@gmx.at> wrote:

I have the following problem: my dataset contains some events (points) and a studyarea, I used some spatstat functions and now I want to use the bandwidth estimation mse2d() in the splancs package. My problem is to convert the spatstat owin-object (studyarea) to use it in the splancs package. This is the structure of my studyarea:

str(studyarea)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
The output says that 'studyarea' is an object of class 'SpatialPolygonsDataFrame', not an object of class 'owin'.

The SpatialPolygonsDataFrame class is part of the 'sp' package. Since the 'splancs' package depends on 'sp', I would have expected that splancs could cope with this object.

But if you *did* have an object of class 'owin' (from spatstat) that you wanted to convert to a SpatialPolygons object, you could just apply the following function to it:

owin2SP <- function(x) {
   stopifnot(is.owin(x))
   x <- as.polygonal(x)
   closering <- function(df) { df[c(seq(nrow(df)), 1), ] }
   pieces <- lapply(x$bdry,
function(p) { Polygon(coords=closering(cbind(p$x,p$y)), hole=is.hole.xypolygon(p)) })
   whole <- Polygons(pieces, "1")
   SpatialPolygons(list(whole))
}


regards
Adrian Baddeley

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to