Pit Strehl
Pit Strehl

Reputation: 21

R combine two lists of sfc_polygons

Hej, I have two lists of polygons. The first one is a list of 1 polygon (circle) The second is a list of 260 polygons (260 rectangles). See the first picture (two lists of polygons).

Now I want to keep all the rectangles that are touched by the circle. See picture 2 merge and 3 result.

Does somebody has any idea? There are serveral things. st_combine, st_intersection - but their are not useable for this problem.

Upvotes: 0

Views: 417

Answers (2)

Edzer Pebesma
Edzer Pebesma

Reputation: 4121

Suppose your blocks are in a, and your circle in b; have you tried

a[lenghts(st_intersects(a, b)) > 0]

?

Upvotes: 1

Calum You
Calum You

Reputation: 15072

Without a reprex it's hard to give a full answer, but I think you want to use st_intersects. This can take two sf objects and return either a list of vectors of pairs that intersect (sparse = TRUE) or a full logical matrix of whether those indices intersect (sparse = FALSE). In this case, I would use the latter, and then appropriate filter to get only the rows you want.

Upvotes: 0

Related Questions