I am migrating code from sp package to the newer sf package. My previous code I had a polygon SpatialDataFrame (censimentoMap) and a SpatialPointDataFrame (indirizzi.sp) and I got the polygon cell id ("Cell110") for each point laying within with the instruction below:
points.data <- over(indirizzi.sp, censimentoMap[,"Cell110"])
Actually I created two sf objects:
shape_sf <- st_read(dsn = shape_dsn)
shape_sf <- st_transform(x=shape_sf, crs=crs_string)
and
indirizzi_sf = st_as_sf(df, coords = c("lng", "lat"), crs = crs_string)
And I am looking for the sf equivalent of the above instruction... Migth it be:
ids<-sapply(st_intersects(x=indirizzi_sf,y=shshape_sfpeCrif), function(z) if (length(z)==0) NA_integer_ else z[1])
cell_ids <- shape_sf[ids,"Cell110"]