I have a CSV file (about 1,000,000 georeferenced points) which contains point_id/latitude/longitude. I also have a shapefile which represents a grid cell_id/xmin/xmax/ymin/ymax. I am trying to join the grid attributes (specifically the cell_id) to the points from my CSV file. Basically I want to know in which cell the points fall.
So my output would look like that point_id/latitude/longitude/cell_id.
library(sp) points<-read.csv(file = "/Users/input.csv", stringsAsFactors=FALSE) coordinates(points)<- ~longitude+latitude library(sf) grid <- read_sf("/Users/grid.shp") a.data <- raster::intersect(points,grid["cell_id",,,]) points$cell_id <- a.data$cell_id write.csv(points, file = "/Users/points.csv")
However this does not gives me the cell_id but instead returns the point_id twice.
I have also tried using
over but it yielded an error message.