ST_Relate function
The ST_Relate function takes two geometries and a Dimensionally Extended 9 Intersection Model (DE-9IM) matrix as input parameters. If the given geometries meet the conditions specified by the matrix, it returns 1. Otherwise, it returns 0.
If any of the given 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.
This function can also be called as a method.
Syntax
Parameters
- geometry1
- A value of type ST_Geometry or one of its subtypes that represents the geometry that is tested against geometry2.
- geometry2
- A value of type ST_Geometry or one of its subtypes that represents the geometry that is tested against geometry1.
- matrix
- A value of CHAR(9) that represents the DE-9IM matrix which is to be used for the test of geometry1 and geometry2.
Return type
INTEGER
Example
The following code 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, 'T*T***T**') "Overlaps ",
ST_Relate(a.geometry, b.geometry, 'T*T***FF*') "Contains ",
ST_Relate(a.geometry, b.geometry, 'T*F**F***') "Within "
ST_Relate(a.geometry, b.geometry, 'T********') "Intersects",
ST_Relate(a.geometry, b.geometry, '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