Name

ST_Relate — 1st Version tests if a Geometry is spatially related to another Geometry as specified by a intersection pattern matrix. 2nd Version returns the DE-9IM (Dimensionally Extended 9 Intersection Model) for two geometries.

Synopsis

boolean ST_Relate(bytea geomA, bytea geomB, varchar PatternMatrix);

varchar ST_Relate(bytea geomA, bytea geomB);

Alias

Relate

Description

1st Version Tests if a Geometry is spatially related to another Geometry by testing for intersections between the interior, boundary and exterior of the two Geometries values as specified by the intersection pattern matrix.

Returns True if the DE-9IM IntersectionMatrix for the two Geometrys match a given intersection Pattern Matrix.

2nd Version returns the DE-9IM (Dimensionally Extended 9 Intersection Model) for two geometries.

Spatial standards define just ST_Relate 1st version.

[Note]

GeometryCollections are unsupported

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
2.1.1.27.2.19.17.2.8.15.1.25

Examples

---1st Version
--Test if 2 polygons overlap
SELECT ST_Relate(PA,PB,'T*T***T**') from 
 (SELECT ST_GeomFromText('POLYGON ((10 30, 0 10, 30 20, 30 30, 20 40, 10 30))') as PA, 
         ST_GeomFromText('POLYGON ((10 40, 20 40, 20 20, 10 20, 10 40))') as PB) as foo;
--Result
TRUE

---2nd Version
SELECT ST_Relate(PA,PB) from 
(SELECT ST_GeomFromText('POLYGON ((10 30, 0 10, 30 20, 30 30, 20 40, 10 30))') as PA, 
        ST_GeomFromText('POLYGON ((10 40, 20 40, 20 20, 10 20, 10 40))') as PB) as foo;

--Result
212101212

Related functions

ST_Disjoint, ST_Touches, ST_Crosses, ST_Within, ST_Overlaps