5

I am using GeoDjango with the PostGIS backend. Given two polygons I want to check if they overlap. I mean, they have interior points in common. If we check

A.function(B)

In the following picture "Example 1" would be False, "Example 2", would be False (cause they only have edges in common) and "Example 3" Would be True, cause they have interior points in common

Examples

3 Answers 3

6

You could use st_intersects with st_touches to find polygons that overlap:

select st_intersects(a.geom,b.geom) and not st_touches(a.geom,b.geom) as overlap
from polygon_a a, polygon_b b;

Returns true if polygons share interior points returns false if polygons only share a boundary or do not intersect.

5

Use ST_Overlaps function: https://postgis.net/docs/ST_Overlaps.html

WHERE ST_Overlaps(a.geom, b.geom)

Returns TRUE if geometry A and B "spatially overlap". Two geometries overlap if they have the same dimension, each has at least one point not shared by the other (or equivalently neither covers the other), and the intersection of their interiors has the same dimension. The overlaps relationship is symmetrical.

1
  • ST_Overlaps requires that the two arguments have points that are NOT in common. So it doesn't detect polygons which are fully covered by another one.
    – dr_jts
    Commented Feb 27, 2023 at 20:40
1

Since ST_Intersects would return True for example 2, I don't think there is a predefined operation in PostGIS to do what you want so you get to explore the world of the Dimensionally Extended 9-Intersection Model.

So you want Interior to Interior as the result of a ST_Relate function call, which I think is going to be something like:

WHERE ST_Intersects(a.geom, b.geom)
  AND ST_Relate(a.geom, b.geom, '2********')
  

So there has to be an intersection but the result must be of dimension 2 (i.e. a polygon not a line).

2
  • 4
    You can also use a DE9IM mask of T******** (which is equivalent for areas).
    – dr_jts
    Commented Feb 27, 2023 at 17:41
  • 2
    See this question for a potential robustness issue to be aware of: gis.stackexchange.com/questions/407520/…
    – dr_jts
    Commented Feb 27, 2023 at 17:42

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.