ST_Relate
ST_Relate takes two geometries and a Dimensionally Extended 9 Intersection Model (DE-9IM) matrix as input parameters and returns 1 if the given geometries meet the conditions specified by the matrix. Otherwise, 0 (zero) is returned.
If any of the given geometries is null or empty, then null is returned.
If the second geometry is not represented in the same spatial reference system as the first geometry, the second geometry will be converted to the other spatial reference system.
Syntax
Parameters
- geometry1
- A value of one of the seven distinct spatial data types that represents the geometry that is tested against geometry2.
- geometry2
- A value of one of the seven distinct spatial data types that represents the geometry that is tested against geometry1.
- matrix
- A value of CHAR(9) that represents the DE-9IM matrix that is to be used for the test of geometry1 and geometry2.
Return type
INTEGER
Example
The following example creates two
separate polygons. Then, the ST_Relate function is used to determine
several relationships between the two polygons. For example, whether
the two polygons overlap.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_polys (id INTEGER, geometry ST_Polygon)
INSERT INTO sample_polys
VALUES (1,
ST_Polygon('polygon ( (40 120, 90 120, 90 150, 40 150, 40 120) )', 0))
INSERT INTO sample_polys
VALUES (2,
ST_Polygon('polygon ( (30 110, 50 110, 50 130, 30 130, 30 110) )', 0))
SELECT ST_Relate(a.geometry, b.geometry, CHAR('T*T***T**') "Overlaps ",
ST_Relate(a.geometry, b.geometry, CHAR('T*T***FF*') "Contains ",
ST_Relate(a.geometry, b.geometry, CHAR('T*F**F***') "Within "
ST_Relate(a.geometry, b.geometry, CHAR('T********') "Intersects",
ST_Relate(a.geometry, b.geometry, CHAR('T*F**FFF2') "Equals "
FROM sample_polys a, sample_polys b
WHERE a.id = 1 AND b.id = 2
Results:
Overlaps Contains Within Intersects Equals
----------- ----------- ----------- ----------- -----------
1 0 0 1 0
