if (require("spatstat.geom") && require("sp")) {
diamond <- list(x = c(1,2,1,0), y = c(1,2,3,2)) # anti-clockwise
diamond.owin <- owin(poly = diamond)
diamond.sp <- Polygon(lapply(diamond, rev)) # clockwise
stopifnot(identical(xylist(diamond.sp), list(diamond)))
diamond.owin_from_sp <- as.owin(diamond.sp)
stopifnot(all.equal(diamond.owin, diamond.owin_from_sp))
## similarly works for Polygons and SpatialPolygons
diamond.Ps <- as(diamond.sp, "Polygons")
stopifnot(identical(diamond.owin, as.owin(diamond.Ps)))
diamond.SpPs <- SpatialPolygons(list(diamond.Ps))
stopifnot(identical(xylist(diamond.SpPs), list(diamond)))
stopifnot(identical(diamond.owin, as.owin(diamond.SpPs)))
}
Run the code above in your browser using DataLab