Describe the bug
After you run a st_union operation on an sf multipolygon, running st_within(another_polygon, unionised_polygon) with this unionised_polygon results in mostly empty matches.
To Reproduce
The below script creates a reproducible example of this behaviour:
library(sf)
library(dplyr)
# read in original polygon
nc <- st_read(system.file("shape/nc.shp", package="sf"))
# create a grouping variable
nc$group <- rep(1:4, each=25)
# create a new grouped sf object using st_union()
nc_grouped <-
nc %>%
group_by(group) %>%
summarise(geometry=st_union(geometry))
plot(nc %>% st_geometry())
plot(nc_grouped %>% st_geometry())
# see what polygons are within the groupings
within_matches <- nc %>%
st_geometry() %>%
st_within(nc_grouped)
print(within_matches)
The original polygon is:
And the second polygon to check if the first is within it is:
In this case, I will get the following matches as an output:
Sparse geometry binary predicate list of length 100, where the predicate was `within'
first 10 elements:
1: (empty)
2: 1
3: 1
4: (empty)
5: (empty)
6: (empty)
7: (empty)
8: (empty)
9: 1
10: 1
However, because these are the exact same geometries, they should all match, not be empty.
Describe the bug After you run a st_union operation on an sf multipolygon, running
st_within(another_polygon, unionised_polygon)
with this unionised_polygon results in mostly empty matches.To Reproduce
The below script creates a reproducible example of this behaviour:
The original polygon is:
And the second polygon to check if the first is within it is:
![image](https://user-images.githubusercontent.com/52495554/141928381-513d960c-327e-4e48-a3c0-95903b4147f5.png)
In this case, I will get the following matches as an output:
However, because these are the exact same geometries, they should all match, not be empty.