ST_Overlaps function

The ST_Overlaps function takes two geometries as input parameters. If the intersection of the geometries results in a geometry of the same dimension but is not equal to either of the given geometries, it returns 1 . Otherwise, it returns 0 (zero).

If any of the two geometries is null or is empty, then null is returned.

If the second geometry is not represented in the same spatial reference system as the first geometry, it will be converted to the other spatial reference system.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_Overlaps(geometry1,geometry2 )

Parameters

geometry1
A value of type ST_Geometry or one of its subtypes that represents the geometry that is tested to overlap with geometry2.
geometry2
A value of type ST_Geometry or one of its subtypes that represents the geometry that is tested to overlap with geometry1.

Return type

INTEGER

Examples

Example 1
This example illustrates the use of ST_Overlaps. Various geometries are created and inserted into the SAMPLE_GEOMETRIES table

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geometries (id INTEGER, geometry ST_Geometry)

INSERT INTO sample_geometries
  VALUES
   (1, ST_Point (10, 20, 1)),
   (2, ST_Point ('point(41 41)', 1) ),
   (10, ST_LineString('linestring(1 10, 3 12, 10 10)', 1) ),
   (20, ST_LineString('linestring(50 10, 50 12, 45 10)', 1)),
   (30, ST_LineString('linestring(50 12, 50 10, 60 8)', 1)),
   (100, ST_Polygon('polygon((0 0, 0 40, 40 40, 40 0, 0 0))', 1)),
   (110, ST_Polygon('polygon((30 10, 30 30, 50 30, 50 10, 30 10))', 1)),
   (120, ST_Polygon('polygon((0 50, 0 60, 40 60, 40 60, 0 50))', 1))
Example 2
This example finds the IDs of points that overlap.

SELECT sg1.id, sg2.id
  CASE ST_Overlaps (sg1.geometry, sg2.geometry)
    WHEN 0 THEN 'Points_do_not_overlap'
    WHEN 1 THEN 'Points_overlap'
    END 
  AS OVERLAP
  FROM sample_geometries sg1, sample_geometries sg2
  WHERE sg1.id < 10 AND sg2.id < 10 AND sg1.id >= sg2.id
Results:

ID          ID         OVERLAP
----------- ---------- ------------------------
          1          1 Points_do_not_overlap
          2          1 Points_do_not_overlap
          2          2 Points_do_not_overlap
Example 3
This example finds the IDs of lines that overlap.

SELECT sg1.id, sg2.id
  CASE ST_Overlaps (sg1.geometry, sg2.geometry)
    WHEN 0 THEN 'Lines_do_not_overlap'
    WHEN 1 THEN 'Lines_overlap'
    END 
  AS OVERLAP
  FROM sample_geometries sg1, sample_geometries sg2
  WHERE sg1.id >= 10 AND sg1.id < 100 
    AND sg2.id >= 10 AND sg2.id < 100
    AND sg1.id >= sg2.id
Results:

ID          ID         OVERLAP
----------- ---------- ------------------------
         10         10 Lines_do_not_overlap
         20         10 Lines_do_not_overlap
         30         10 Lines_do_not_overlap
         20         20 Lines_do_not_overlap
         30         20 Lines_overlap
         30         30 Lines_do_not_overlap
Example 4
This example finds the IDs of polygons that overlap.

SELECT sg1.id, sg2.id
  CASE ST_Overlaps (sg1.geometry, sg2.geometry)
    WHEN 0 THEN 'Polygons_do_not_overlap'
    WHEN 1 THEN 'Polygons_overlap'
    END 
  AS OVERLAP
  FROM sample_geometries sg1, sample_geometries sg2
  WHERE sg1.id >= 100 AND sg2.id >= 100 AND sg1.id >= sg2.id
Results:

ID          ID         OVERLAP
----------- ---------- ------------------------
        100        100 Polygons_do_not_overlap
        110        100 Polygons_overlap
        120        100 Polygons_do_not_overlap
        110        110 Polygons_do_not_overlap
        120        110 Polygons_do_not_overlap
        120        120 Polygons_do_not_overlap