Learn R Programming

polyCub (version 0.9.1)

sfg2gpc: Convert polygonal "sfg" to "gpc.poly"

Description

Package polyCub implements a converter from class "(MULTI)POLYGON" of package sf to "gpc.poly" of package gpclib such that polyCub.exact.Gauss can be used with simple feature polygons.

Usage

sfg2gpc(object)

Value

The converted polygon of class "gpc.poly". If package gpclib is not available, sfg2gpc will just return the pts slot of the "gpc.poly" (no formal class) with a warning.

Arguments

object

a "POLYGON" or "MULTIPOLYGON" "sfg" object.

Author

Sebastian Meyer

See Also

xylist

Examples

Run this code
## use example polygons from
example(plotpolyf, ask = FALSE)
letterR  # a simple "xylist"

letterR.sfg <- sf::st_polygon(lapply(letterR, function(xy)
    rbind(cbind(xy$x, xy$y), c(xy$x[1], xy$y[1]))))
letterR.sfg
stopifnot(identical(letterR, xylist(letterR.sfg)))
# \dontshow{
stopifnot(identical(rep(letterR, 2),
    xylist(sf::st_multipolygon(list(letterR.sfg, letterR.sfg)))))
# }
## convert sf "POLYGON" to a "gpc.poly"
letterR.gpc_from_sfg <- sfg2gpc(letterR.sfg)
letterR.gpc_from_sfg
# \dontshow{
if (is(letterR.gpc_from_sfg, "gpc.poly") && requireNamespace("spatstat.geom")) {
    letterR.xylist_from_gpc <- xylist(letterR.gpc_from_sfg) # with hole info
    stopifnot(identical(letterR, lapply(letterR.xylist_from_gpc, `[`, 1:2)))
}# }

Run the code above in your browser using DataLab