Home > Blockchain >  point in polygon with `sf`
point in polygon with `sf`

Time:07-26

i am trying to get that each point falls into the respective polygon. Given that I could not do it by aplying sp::over I am trying right now with the tidyverse::sf . I hope that someone can help me with this issue.

points in squares

CodePudding user response:

I agree with @Jindra Lacko - it is not quite clear what the task is.

But as far as I understand you are looking for this:

library(data.table)
library(sf)
library(sfheaders)
library(tidyverse)
library(mapview)
library(leaflet)
library(leafem)
library(tidyverse)

## your code ##
# coordinates = ''
# DT <- ''
# cols <- ''
# DT['']
# buffers <- ''

res_list <- lapply(seq(nrow(buffers)), function(x) st_intersection(buffers[x,], coordinates))

res_list 


[[1]]
Simple feature collection with 18 features and 2 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -9 ymin: 1 xmax: -1 ymax: 9
CRS:           NA
First 10 features:
    ID id     geometry
1    1  6 POINT (-9 4)
1.1  1  9 POINT (-6 1)
1.2  1 11 POINT (-3 4)
1.3  1 13 POINT (-9 4)
1.4  1 24 POINT (-8 4)
1.5  1 26 POINT (-7 4)
1.6  1 31 POINT (-9 9)
1.7  1 35 POINT (-1 8)
1.8  1 45 POINT (-9 6)
1.9  1 56 POINT (-9 4)

...

[[4]]
Simple feature collection with 14 features and 2 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 1 ymin: -7 xmax: 9 ymax: -1
CRS:           NA
First 10 features:
    ID id     geometry
4    4  4 POINT (1 -3)
4.1  4 22 POINT (7 -4)
4.2  4 27 POINT (1 -3)
4.3  4 28 POINT (7 -2)
4.4  4 32 POINT (9 -7)
4.5  4 44 POINT (9 -1)
4.6  4 50 POINT (6 -5)
4.7  4 54 POINT (1 -3)
4.8  4 72 POINT (7 -4)
4.9  4 77 POINT (1 -3)
  • Related