I have a dataframe of points and a shapefile with about 2000 named polygon. I'm trying to determine which polygon each point is in, but I'm having a difficult time. I tried this solution from google:
y22Sample$region = apply(samplell, 1, function(row) { palner = st_transform(shape, 2163) coords = as.data.frame(matrix(row, nrow=1, dimnames = list("", c("x", "y")))) pnt_sf = st_transform(st_sfc(st_point(row),crs = 4326), 2163) palner[which(st_intersects(pnt_sf, palner, sparse = FALSE)), ]$NAME_1 })
But this isn't completing, even for just a sample of 1000 points (after running for over 1 hour). This method will be absolutely impossible for my full dataframe of over 5 million points.
Does anybody else have a good solution? I would appreciate some help.