1

I have a multipolygon shapefile that contains thousands of records with a spatial and temporal component. I'd like to be able to identify records that overlap (the amount of overlap doesn't really matter at the moment).

Is this possible in R?

I don't have a reproducible example, but here is an image of what I'm describing. It is a multipolygon with two records that clearly overlap. I want to filter my data such all overlapping polygons are returned.

enter image description here

1
  • 1
    st_overlaps returns a list (or matrix) of which feature overlaps which feature. Or maybe you want st_intersects? (overlapping is a special case of intersection where one is not contained in the other). Have you tried these? Your example (unclear because of the shading) looks like they intersect and overlap.
    – Spacedman
    Commented Jul 29, 2022 at 7:37

1 Answer 1

1

Considering these four polygons quickly drawn out in QGIS for example:

enter image description here

Then you can see how the four polygons relate using the various spatial predicate operators:

> st_overlaps(lap, sparse=FALSE)
      [,1]  [,2]  [,3]  [,4]
[1,] FALSE FALSE FALSE FALSE
[2,] FALSE FALSE FALSE FALSE
[3,] FALSE FALSE FALSE  TRUE
[4,] FALSE FALSE  TRUE FALSE

3 and 4 are the only ones that "overlap" in this sense. 1 and 2 don't overlap because 2 is fully inside 1. Polygons do not "overlap" themselves.

However 1 intersects with 2, and 3 intersects with 4. Note also that polygons "intersect" with themselves:

> st_intersects(lap, sparse=FALSE)
      [,1]  [,2]  [,3]  [,4]
[1,]  TRUE  TRUE FALSE FALSE
[2,]  TRUE  TRUE FALSE FALSE
[3,] FALSE FALSE  TRUE  TRUE
[4,] FALSE FALSE  TRUE  TRUE

You can also do stuff like "contains" - 1 contains 2 but 2 does not contain 1. Polygons do contain themselves:

> st_contains(lap, sparse=FALSE)
      [,1]  [,2]  [,3]  [,4]
[1,]  TRUE  TRUE FALSE FALSE
[2,] FALSE  TRUE FALSE FALSE
[3,] FALSE FALSE  TRUE FALSE
[4,] FALSE FALSE FALSE  TRUE

Note I've not constructed polygons that only touch along edges or nodes. Mostly because I'm never sure if the predicate functions think these overlap or intersect - but there's st_touches for that. If you want the full set of possibilities of polygon relations then use st_relate and work out what you want from the DE9-IM model string.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.