I have an issue where I'm spatially joining points to grid squares, but sometimes they're just barely out of range. To address this, I want to identify which points become incorporated into these original grid cells, when applying a buffer of 15km.
What is the best way to go about this using the
sf package? How do I create a new buffered-square join I can directly compare to the original squares? Particularly since this new buffered join will overlap several other grid cells, such that many points will be double or quadruple counted?
At the end of the day, I'd like to examine an object or dataframe that identifies every original square and the points that are 'missed' just outside it, within that 15km border.
library(tidyverse) library(sf) gridpolygons <- read_rds('Data/gridpolys.rds') %>% st_as_sf gridpolygons.metersproj <- st_transform(gridpolygons, 32119) # create 15 km buffer and transform back to wgs84 buffer15km <- st_buffer( gridpolygons.metersproj, dist = 15000) %>% st_transform(4326) points <- st_as_sf(getPoints()) # Pulls shapefile of points into sf object # (custom fn; then conversion to sf object) # Original join cell_points <- st_join(gridpolygons, points) # Buffer object join? e.g., # buffer_points <- st_join(buffer15km, points)#? # Or alternate method to avoid double-counting, that I can compare # compare easily to first spatial join? # Method that cuts a hole out of the buffered polygon # to make a polygon that's just border, and then joins points with replacement?
The objective is to identify the points that are 'near misses' from being joined to each cell, or within 15km of the grid cell.