if (require("rgeos") && require("sf")) {
## use example polygons from
example(plotpolyf, ask = FALSE)
letterR # a simple "xylist"
letterR.sfg <- st_polygon(lapply(letterR, function(xy)
rbind(cbind(xy$x, xy$y), c(xy$x[1], xy$y[1]))))
print(letterR.sfg)
stopifnot(identical(letterR, xylist(letterR.sfg)))
# \dontshow{
stopifnot(identical(rep(letterR, 2),
xylist(st_multipolygon(list(letterR.sfg, letterR.sfg)))))
# }
## convert sf "POLYGON" to a "gpc.poly"
letterR.gpc_from_sfg <- sfg2gpc(letterR.sfg)
print(letterR.gpc_from_sfg)
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 DataCamp Workspace