x = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1))
x1 = 0.1 * x + 0.1
x2 = 0.1 * x + 0.4
x3 = 0.1 * x + 0.7
y = x + 3
y1 = x1 + 3
y2 = x2 + 3
y3 = x3 + 3
library(sp)
p = Polygons(list( Polygon(x[5:1,]), Polygon(x2), Polygon(y2), Polygon(x3),
Polygon(y[5:1,]), Polygon(y1), Polygon(x1), Polygon(y3)), "ID1")
if (require("rgeos")) {
r = createSPComment(SpatialPolygons(list(p)))
comment(r)
comment(r@polygons[[1]])
scan(text = comment(r@polygons[[1]]), quiet = TRUE)
library(sf)
a = as.sf(r)
summary(a)
}
Run the code above in your browser using DataLab