Learn R Programming

polyCub (version 0.7.1)

coerce-sp-methods: Coerce "SpatialPolygons" to "owin"

Description

Package polyCub implements coerce-methods (as(object, Class)) to convert "'>SpatialPolygons" (or "'>Polygons" or "'>Polygon") to "owin". They are also available as as.owin.* functions to support polyCub.midpoint. However, these are no registered S3 methods for as.owin, since package spatstat is optional. Note that the maptools package contains an alternative implementation of coercion from "SpatialPolygons" to "owin" (and reverse), and R will use the S4 coerce-method that was loaded last, and prefer the as.owin.SpatialPolygons S3-method exported from maptools if attached.

Usage

as.owin.SpatialPolygons(W, ...)

as.owin.Polygons(W, ...)

as.owin.Polygon(W, ...)

Arguments

W

an object of class "SpatialPolygons", "Polygons", or "Polygon".

...

further arguments passed to owin.

Examples

Run this code
# NOT RUN {
if (require("spatstat") && 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
    diamond.owin_from_sp <- as(diamond.sp, "owin")
    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(diamond.owin, as.owin(diamond.SpPs)))
}
# }

Run the code above in your browser using DataLab