Spatial functions can be used to determine the spatial relationships between geometries.
- ST_Contains: returns 1 if g1 completely contains g2.
- ST_Crosses: returns 1 if the left geometry spatially crosses the right one.
- ST_Disjoint: returns 1 if the left geometry is spatially disjoint from the right one.
- ST_Equals: returns 1 if the left geometry is spatially equal to the right one.
- ST_Intersects: returns 1 if the left geometry spatially intersects the right one.
- ST_Overlaps: returns 0 if the left geometry spatially overlaps the right one.
- ST_Relate: returns 1 if 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 1 if the left geometry spatially touches the right one.
- ST_Within: returns 1 if the left geometry is spatially enclosed within the right one.
ST_Contains
ST_Contains(g1, g2)
- Description: This function returns 1 if g1 completely contains g2. A value of 1 indicates
true, and a value of 0 indicates false.
Note g1 does not contain its boundary.
- Data type of the return value: INT.
- Example:
Returned results:SELECT ST_Contains(ST_GeometryFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))'), ST_GeometryFromText('POINT (2 2)'));
+-----------------------------------------------------------------------------------------------------+ |ST_Contains(ST_GeometryFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))'), ST_GeometryFromText('POINT (2 2)')) | +-----------------------------------------------------------------------------------------------------+ | 1 |
ST_Crosses
ST_Crosses(g1, g2)
- Description: This function returns 1 if the left geometry spatially crosses the right one. A value of 1 indicates true, and a value of 0 indicates false.
- Data type of the return value: INT.
- Example:
Returned results: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)')) | +----------------------------------------------------------------------------------------------+ | 0 |
ST_Disjoint
ST_Disjoint(g1, g2)
- Description: This function returns 1 if the left geometry is spatially disjoint from the right one. A value of 1 indicates true, and a value of 0 indicates false.
- Data type of the return value: INT.
- Example:
Returned results: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)')) | +--------------------------------------------------------------------------------------------------+ | 1 |
ST_Equals
ST_Equals(g1, g2)
- Description: This function returns 1 if the left geometry is spatially equal to the right one. A value of 1 indicates true, and a value of 0 indicates false.
- Data type of the return value: INT.
- Example:
Returned results: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)')) | +------------------------------------------------------------------------------------------------+ | 0 |
ST_Intersects
ST_Intersects(g1, g2)
- Description: This function returns 1 if the left geometry spatially intersects the right one. A value of 1 indicates true, and a value of 0 indicates false.
- Data type of the return value: INT.
- Example:
Returned results: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)')) | +----------------------------------------------------------------------------------------------------+ | 0 |
ST_Overlaps
ST_Overlaps(g1, g2)
- Description: This function returns 0 if the left geometry spatially overlaps the right one. A value of 0 indicates true, and a value of 1 indicates false.
- Data type of the return value: INT.
- Example:
Returned results: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))')) | +---------------------------------------------------------------------------------------------------------------------------------+ | 1 |
ST_Relate
ST_Relate(g1, g2, s1)
- Description: This function returns 1 if the left and right geometries meet the conditions specified by a DE-9IM matrix. A value of 1 indicates true, and a value of 0 indicates false. A third input of the VARCHAR type indicates that the relationship is accepted.
- Data type of the return value: INT.
- Example:
Returned results: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****') | +--------------------------------------------------------------------------------------------------------------------------+ | 0 |
ST_Touches
ST_Touches(g1, g2)
- Description: This function returns 1 if the left geometry spatially touches the right one. A value of 1 indicates true, and a value of 0 indicates false.
- Data type of the return value: INT.
- Example:
Returned results: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)')) | +-------------------------------------------------------------------------------------------------+ | 0 |
ST_Within
ST_Within(g1, g2)
- Description: This function returns 1 if the left geometry is spatially enclosed within the right one. A value of 1 indicates true, and a value of 0 indicates false.
- Data type of the return value: BOOLEAN.
- Example:
Returned results: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)')) | +-------------------------------------------------------------------------------------------------+ | 0 |