remove.holes | R Documentation |
Removes or returns all holes (null geometry) in sf polygon class objects
remove.holes(x, only.holes = FALSE)
x |
sf POLYGON or MULTIPOLYGON object |
only.holes |
Delete holes (FALSE) or returns only holes (FALSE) |
A hole is considered a polygon within a polygon (island) representing null geometry. If you want to return only holes, no longer NULL, use keep = TRUE. To delete holes use default only.holes = FALSE. Single part features will be returned regardless of input.
sf POLYGON object
Jeffrey S. Evans <jeffrey_evans@tnc.org>
library(sf)
p <- sf::st_as_sf(sf::st_sfc(
sf::st_polygon(list(
cbind(c(2,4,4,1,2),c(2,3,5,4,2)),
cbind(c(2.33, 2.05, 3.25, 3.25, 2.33),
c(3.00, 3.56, 3.95, 3.46, 3.00)))),
sf::st_polygon(list(
cbind(c(5,4,2,5),c(2,3,2,2)))),
sf::st_polygon(list(
cbind(c(4,4,5,10,4),c(5,3,2,5,5)),
cbind(c(5,6,6,5,5),c(4,4,3,3,4))
))))
p$ID <- 1:3
rh <- remove.holes(p)
kh <- remove.holes(p, only.holes=TRUE)
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2))
plot(st_geometry(p), main="Original with holes")
plot(st_geometry(rh), main="holes removed only.holes=FALSE")
plot(st_geometry(kh), main="return holes only.holes=TRUE")
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.