How the ST_Overlaps Geometry Checker works, and what it assumes

ST_Overlaps(A, B) is true for two geometries of the same dimension that share some of their space while each keeps a part the other does not cover. Two polygons must share an area and each extend beyond the other; two lines must share a stretch of line and each continue beyond it. The DE-9IM patterns are T*T***T** for points and polygons and 1*T***T** for lines.

It is a narrow test, and it is false in several cases that look like overlap at first sight. When one polygon lies completely inside the other, that is containment. When they are identical, they are equal. A line and a polygon can never overlap, whatever they do, because they have different dimensions. The sentence under the verdict names whichever of these applies.

To get the overlapping part as a geometry, run the pair through ST_Intersection; to merge them, ST_Union.

Where this comes up in GIS work

  • Finding land parcels, sales territories or service areas whose boundaries were drawn over each other.
  • Checking a polygon layer for overlaps that should not exist before an area total is calculated.
  • Testing whether two surveyed lines share a stretch of their route.

A worked example

Two squares that share a corner region:

A: POLYGON ((0 0, 6 0, 6 6, 0 6, 0 0))
B: POLYGON ((3 3, 9 3, 9 9, 3 9, 3 3))

ST_Overlaps(A, B) = true
DE-9IM matrix: 212101212

Each square has area outside the other (the 2 in the third column of the first row and in the first column of the last row). Test the small square POLYGON ((2 2, 5 2, 5 5, 2 5, 2 2)) against POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0)) instead, and ST_Overlaps is false while ST_Within is true: one inside the other is containment, not overlap. For lines, LINESTRING (0 0, 6 0) and LINESTRING (3 0, 9 0) overlap: they share the stretch from 3 to 6.

Using the ST_Overlaps Geometry Checker

  1. Paste the first geometry into Geometry A, or select Load example.
  2. Paste a geometry of the same kind into Geometry B: polygon with polygon, line with line, or point with point.
  3. Select Check ST_Overlaps, or press Ctrl + Enter (Cmd + Enter on a Mac).
  4. Read the verdict and its explanation, then run ST_Intersection to get the overlapping part.

When the output looks wrong

ST_Overlaps is false although one polygon covers part of the other
Check whether one of them is entirely inside the other. Containment is not overlap: ST_Overlaps needs each geometry to have a part outside the other. The explanation under the verdict says which case you have.
A line through a polygon does not overlap it
ST_Overlaps only compares geometries of the same dimension. A line and a polygon can cross or intersect but never overlap; use ST_Crosses or ST_Intersects for that pair.
Two lines that cross do not overlap
Lines overlap only when they share a stretch of line. Meeting at a single point is crossing, which ST_Crosses reports.
Two identical polygons do not overlap
Identical geometries are equal, not overlapping, because neither has a part outside the other. ST_Equals is the predicate that is true for them.

Questions about the ST_Overlaps Geometry Checker

When is ST_Overlaps true?

When A and B have the same dimension, their interiors meet in something of that same dimension, and each has a part outside the other. The DE-9IM pattern is T*T***T** for points and polygons and 1*T***T** for lines.

How is it different from ST_Intersects?

ST_Intersects is true for any shared point, including touching, crossing and containment. ST_Overlaps is the narrow case of two same-kind geometries partly covering each other.

How do I get the overlapping area?

Run the two polygons through ST_Intersection, which returns the shared part as a geometry, with its area measured.

Does it work on geometry collections?

A FeatureCollection of polygons is compared as the union of its polygons, and a collection of lines as one MultiLineString. The page says when it has done this.

Is my data sent anywhere?

No. The check runs in your browser.