st_intersects Vs st_overlaps st_intersects Vs st_overlaps sql sql

st_intersects Vs st_overlaps


From the documentation of PostGIS

http://postgis.net/docs/ST_Intersects.html

If a geometry or geography shares any portion of space then they intersect. Overlaps, Touches, Within all imply spatial intersection. If any of the aforementioned returns true, then the geometries also spatially intersect.

http://postgis.net/docs/ST_Overlaps.html

Returns TRUE if the Geometries "spatially overlap". By that we mean they intersect, but one does not completely contain another.

The difference is: If two geometries overlap 100%, they do not overlap any more.

Here is a POSTGIS example:

SELECT ST_Overlaps(a,b) As a_overlap_b, ST_Intersects(a, b) As a_intersects_b, ST_Contains(b, a) As b_contains_aFROM (SELECT     ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326)  As a,    ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326)  As b)    As foo;    -- INTERSECT is TRUE, OVERLAP is FALSE because B equals A    SELECT ST_Overlaps(a,b) As a_overlap_b, ST_Intersects(a, b) As a_intersects_b, ST_Contains(b, a) As b_contains_aFROM (SELECT     ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326)  As a,    ST_Polygon(ST_GeomFromText('LINESTRING(1 1,4 1,4 4,1 1)'), 4326)  As b)    As foo;    -- INTERSECT is TRUE, OVERLAP is FALSE because B contains A    SELECT ST_Overlaps(a,b) As a_overlap_b, ST_Intersects(a, b) As a_intersects_b, ST_Contains(b, a) As b_contains_aFROM (SELECT     ST_Polygon(ST_GeomFromText('LINESTRING(0 0,2 0,2 2,0 0)'), 4326)  As a,    ST_Polygon(ST_GeomFromText('LINESTRING(1 1,3 1,3 3,1 1)'), 4326)  As b)    As foo;    -- INTERSECT is TRUE, OVERLAP is TRUE because not all of A intersects B and not all of B intersects A