I have two spatial objects, one is points nc_point
(n=50) and the other is polygons sample_polygons
(n=20). Some of the points are fallen in polygons, which can be identified using the nc_point[sample_polygons , ]
function.
My question is how to obtain a subset of all the points that are NOT fallen in any polygons, i.e. the rest of the points?
# points layer contain 50 points
nc_point <- st_read(system.file("shape/nc.shp", package="sf")) %>%
st_centroid()
# the number of polygons is 20
set.seed(1)
sample_polygons <- st_read(system.file("shape/nc.shp", package="sf")) %>%
sample_n(20) %>%
select(geometry) # to mimic a situation where points are only identified using spatial correlation.
# points that fall in polygons can be identified using:
points_in <- nc_point[sample_polygons , ]
# how to find out points that are not fallen in any polygons?
Thanks, Phil