1

I need to run an error-check in R on polygons imported from shape files via sf::st_read. Polygons that share some boundary points are fine, but I need to throw an error if there are polygons that share interior points.

st_intersects tells me that polygons with common boundary points do intersect but I need to know only whether interiors intersect. Is there a fast, simple way to do this?

A simple example: Why would the following polygons' interiors overlap?

A1 <- st_polygon(list(rbind( 
   c(-9724223, 4954258), 
   c(-9724234, 4954063), 
   c(-9724202, 4954049), 
   c(-9724186, 4954169), 
   c(-9724211, 4954252), 
   c(-9724223, 4954258)))) 
tmp <- st_polygon(list(rbind( 
   c(-9724224, 4954255), 
   c(-9724268, 4954013), 
   c(-9724146, 4954008), 
   c(-9724148, 4954135), 
   c(-9724208, 4954257), 
   c(-9724224, 4954255)))) 

A2 <- st_difference(tmp, A1) 
st_intersects(A2, A1) 
st_overlaps(A2, A1) 
st_relate(A2, A1) 
2
  • Have you tried ST_Overlaps? But totally contained does not overlap, is that OK for you?
    – user30184
    Jan 16, 2020 at 1:14
  • @user30184 It seems like it should work, but it fails in an example I appended to my original question.
    – uff da
    Jan 16, 2020 at 19:50

1 Answer 1

2

Are you looking for something like st_relate which implements the DE9-IM relation scheme?

https://en.wikipedia.org/wiki/DE-9IM

This tells you how the exterior, boundary, and interior of two features relate to each other. For example two polygons that only touch at a point have no interior-interior relation (which is coded as F) and a point dimension boundary-boundary relation (coded as 0 for 0-dimension, ie a point).

Two polygons that share a side but don't overlap will have a boundary-boundary relation of 1 (a one-dimensional line) and an interior-interior relation of F. If the interior-interior relation of two polygons is 2 then they have a 2-dimensional area of overlap.

By careful consideration of the DE9IM matrix it is usually possible to test if two objects relate in any way you are interested in, and this can be tested in the pattern parameter to st_relate.

1
  • I like this function. Thanks for pointing it out. It doesn't perform as expected for me in a new example I added to my original question. I'm not sure where my error is. st_relate(A1, st_difference(A2, A1)) seems like it should not overlap in 2d. Obviously, I'm missing something.
    – uff da
    Jan 16, 2020 at 20:12

Your Answer

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

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