Spatial relation functions can be used to determine the spatial relationship between two geometries.

• ST_Contains: returns true only when g1 completely contains g2.
• ST_Crosses: returns true only when the left geometry spatially crosses the right one.
• ST_Disjoint: returns true only when the left geometry is spatially disjoint from the right one.
• ST_Equals: returns true only when the left geometry is spatially equal to the right one.
• ST_Intersects: returns true only when the left geometry spatially intersects the right one.
• ST_Overlaps: returns true only when the left geometry spatially overlaps the right one.
• ST_Relate: returns true only when the left and right geometries meet the conditions specified by a Dimensionally Extended 9 Intersection Model (DE-9IM) matrix. A third input of the VARCHAR type indicates that the relationship is accepted.
• ST_Touches: returns true only when the left geometry spatially touches the right one.
• ST_Within: returns true only when the left geometry is spatially enclosed within the right one.

## ST_Contains

``ST_Contains(g1, g2)``
• Description: This function returns true only when g1 completely contains g2.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Contains(ST_GeometryFromText('POINT (20 20)'), ST_GeometryFromText('POINT (25 25)'));
+----------------------------------------------------------------------------------------+
|ST_Contains(ST_GeometryFromText('POINT (20 20)'), ST_GeometryFromText('POINT (25 25)')) |
+----------------------------------------------------------------------------------------+
|                        false                                                           |``````

## ST_Crosses

``ST_Crosses(g1, g2)``
• Description: This function returns true only when the left geometry spatially crosses the right one.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Crosses(ST_GeometryFromText('POINT (20 20)'), ST_GeometryFromText('POINT (25 25)'))  +
*----------------------------------------------------------------------------------------------+
|ST_Crosses(ST_GeometryFromText('POINT (20 20)'), ST_GeometryFromText('POINT (25 25)'))        |
+----------------------------------------------------------------------------------------------+
|               false                                                                          | ``````

## ST_Disjoint

``ST_Disjoint(g1, g2)``
• Description: This function returns true only when the left geometry is spatially disjoint from the right one.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Disjoint(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))  +
*--------------------------------------------------------------------------------------------------+
|ST_Disjoint(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))        |
+--------------------------------------------------------------------------------------------------+
|                 true                                                                             | ``````

## ST_Equals

``ST_Equals(g1, g2)``
• Description: This function returns true only when the left geometry is spatially equal to the right one.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Equals(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))  +
*--------------------------------------------------------------------------------------------------+
|ST_Equals(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))        |
+--------------------------------------------------------------------------------------------------+
|                 false                                                                             | ``````

## ST_Intersects

``ST_Intersects(g1, g2)``
• Description: This function returns true only when the left geometry spatially intersects the right one.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Intersects(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))  +
*----------------------------------------------------------------------------------------------------+
|ST_Intersects(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))        |
+----------------------------------------------------------------------------------------------------+
|                 false                                                                              | ``````

## ST_Overlaps

``ST_Overlaps(g1, g2)``
• Description: This function returns true only when the left geometry spatially overlaps the right one.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Overlaps(ST_GeometryFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))'), ST_GeometryFromText('POLYGON ((3 3, 3 5, 5 5, 5 3))'))  +
*---------------------------------------------------------------------------------------------------------------------------------+
|ST_Overlaps(ST_GeometryFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))'), ST_GeometryFromText('POLYGON ((3 3, 3 5, 5 5, 5 3))'))        |
+---------------------------------------------------------------------------------------------------------------------------------+
|                 true                                                                                                           | ``````

## ST_Relate

``ST_Relate(g1, g2, s1)``
• Description: This function returns true only when the left and right geometries meet the conditions specified by a DE-9IM matrix. A third input of the VARCHAR type indicates that the relationship is accepted.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Relate(ST_GeometryFromText('LINESTRING (0 0, 3 3)'), ST_GeometryFromText('LINESTRING (1 1, 4 1)'), '****T****')  +
*--------------------------------------------------------------------------------------------------------------------------+
|ST_Relate(ST_GeometryFromText('LINESTRING (0 0, 3 3)'), ST_GeometryFromText('LINESTRING (1 1, 4 1)'), '****T****')        |
+--------------------------------------------------------------------------------------------------------------------------+
|                 false                                                                                                    | ``````

## ST_Touches

``ST_Touches(g1, g2)``
• Description: This function returns true only when the left geometry spatially touches the right one.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Touches(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))  +
*-------------------------------------------------------------------------------------------------+
|ST_Touches(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))        |
+-------------------------------------------------------------------------------------------------+
|                 false                                                                           | ``````

## ST_Within

``ST_Within(g1, g2)``
• Description: This function returns true only when the left geometry is spatially enclosed within the right one.
• Return value type: BOOLEAN.
• Example:
``````SELECT ST_Within(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))  +
*-------------------------------------------------------------------------------------------------+
|ST_Within(ST_GeometryFromText('POINT (50 100)'), ST_GeometryFromText('POINT (150 150)'))        |
+-------------------------------------------------------------------------------------------------+
|                 false                                                                           | ``````