You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
st_no_overlap <- function(polygons) {
centroids <- st_centroid(polygons)
# Voronoi tesselation
voronoi <-
centroids %>%
st_geometry() %>%
st_union() %>%
st_voronoi() %>%
st_collection_extract()
# Put them back in their original order
voronoi <- voronoi[unlist(st_intersects(centroids, voronoi))]
# Keep the attributes
result <- centroids
# Intersect voronoi zones with polygons
st_geometry(result) <-
mapply(function(x, y) st_intersection(x, y),
st_geometry(polygons),
voronoi,
SIMPLIFY = FALSE) %>%
st_sfc(crs = st_crs(polygons))
result
}
I run his example,
pol <- st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0))))
b <- st_sfc(pol, pol + c(.8, .2), pol + c(.2, .8))
cl = sf.colors(3, categorical = TRUE)
plot(st_no_overlap(st_sf(geometry = b)), col = cl)
and get the same nice picture without overlaping.
but this is only in the picture. If I check for overlapping with st_overlaps, I get that the polygons indeed overlap!
st_overlaps(st_no_overlap(st_sf(geometry = b)))
Sparse geometry binary predicate list of length 3, where the predicate was `overlaps'
1: 2, 3
2: 1
3: 1
The same happens with the st_buffer_without_overlap function mentioned in #824, so I am not sure if this has to do with the geometrical operations done in the functions (voronoi, intersections,...) o with the slivers mentioned in #547.
Is there a general way to prevent this behaviour or at least to solve it? Thanks!
The text was updated successfully, but these errors were encountered:
Taking the example from this stackexchange question and his
st_no_overlap
function:I run his example,
and get the same nice picture without overlaping.
but this is only in the picture. If I check for overlapping with
st_overlaps
, I get that the polygons indeed overlap!The same happens with the
st_buffer_without_overlap
function mentioned in #824, so I am not sure if this has to do with the geometrical operations done in the functions (voronoi, intersections,...) o with the slivers mentioned in #547.Is there a general way to prevent this behaviour or at least to solve it? Thanks!
The text was updated successfully, but these errors were encountered: