I am trying to create a new simple feature from two overlapping features. I want to subset all polygons that are fully or partially located within my buffer (red border).
However, the st_overlaps
generates Sparse geometry binary predicate list
. I have honestly no idea how to use this list to subset my original fc to create new geometry?. This suggestion using st_within
does not work: nbrs.buff <- left[st_overlaps(buff, left) %>% lengths > 1, ]
, as it subset all of the files, not ones overed by buffer
. What I am missing?
Here is my dummy example:
# Load data
shp = system.file("shape/nc.shp", package="sf")
my.sf <- st_read(shp, quiet = TRUE)
# Convert crs to projected system to make buffer
my.sf.web<- st_transform(my.sf, 3857)
# Subset the data to create two independent shps
i = 10
# Split datasets in two files
one = my.sf.web[i, ]
left = my.sf.web[-i,]
# Create buffer
buff = st_buffer(one, 40000 ) # distance
# CHeck which polygons overlaps with my buffer
out.overlap = st_overlaps(buff, left)
# Subset the overlapping polygons to create new geometry: DOES NOT WORK??
nbrs.buff <- left[st_overlaps(buff, left) %>% lengths > 1, ]