I am working with spatial data and I need to split a multipolygon into polygons with no intersecting edges. For instance, consider this multipolygon mp:
p <- st_polygon(list(rbind(
c(0, 0),
c(2, 2),
c(0, 2),
c(2, 0),
c(0, 0))))
q <- st_polygon(list(rbind(
c(-4, -4),
c(-2, -2),
c(-4, -2),
c(-2, -4),
c(-4, -4))))
mp <- st_multipolygon(list(p,q))
How can I turn mp into these four polygons?
a <- st_polygon(list(rbind(
c(1, 1),
c(2, 2),
c(0, 2),
c(1, 1))))
b <- st_polygon(list(rbind(
c(1, 1),
c(0, 0),
c(0, 2),
c(1, 1))))
c <- st_polygon(list(rbind(
c(-3, -3),
c(-2, -4),
c(-4, -4),
c(-3, -3))))
d <- st_polygon(list(rbind(
c(-3, -3),
c(-4, -2),
c(-2, -2),
c(-3, -3))))
I already tried to use st_cast, but there are edges that cross
Valid simple features should be non-self intersecting - https://r-spatial.github.io/sf/articles/sf1.html#simple-feature-geometry-types - so not sure if it helps with your real data or not, but passing that
mp
throughst_make_valid()
turns it into a mulitpolygon of 4 polygons and that can be casted:Created on 2023-02-20 with reprex v2.0.2