MySQL 5.6 Reference Manual  /  ...  /  Spatial Relation Functions That Use Object Shapes

#### 12.17.9.1 Spatial Relation Functions That Use Object Shapes

The OpenGIS specification defines the following functions to test the relationship between two geometry values `g1` and `g2`, using precise object shapes. The return values 1 and 0 indicate true and false, respectively, except for `ST_Distance()`, which returns distance values.

• Returns 1 or 0 to indicate whether `g1` completely contains `g2`. This tests the opposite relationship as `ST_Within()`.

• `ST_Crosses()` and `Crosses()` are synonyms. For more information, see the description of `ST_Crosses()`.

• The term spatially crosses denotes a spatial relation between two given geometries that has the following properties:

• The two geometries intersect.

• Their intersection results in a geometry that has a dimension that is one less than the maximum dimension of the two given geometries.

• Their intersection is not equal to either of the two given geometries.

This function returns 1 or 0 to indicate whether `g1` spatially crosses `g2`. If `g1` is a `Polygon` or a `MultiPolygon`, or if `g2` is a `Point` or a `MultiPoint`, the return value is `NULL`.

`ST_Crosses()` and `Crosses()` are synonyms.

• Returns 1 or 0 to indicate whether `g1` is spatially disjoint from (does not intersect) `g2`.

• Returns the distance between `g1` and `g2`.

``````mysql> SET @g1 = Point(1,1);
mysql> SET @g2 = Point(2,2);
mysql> SELECT ST_Distance(@g1, @g2);
+-----------------------+
| ST_Distance(@g1, @g2) |
+-----------------------+
|    1.4142135623730951 |
+-----------------------+``````
• Returns 1 or 0 to indicate whether `g1` is spatially equal to `g2`.

``````mysql> SET @g1 = Point(1,1), @g2 = Point(2,2);
mysql> SELECT ST_Equals(@g1, @g1), ST_Equals(@g1, @g2);
+---------------------+---------------------+
| ST_Equals(@g1, @g1) | ST_Equals(@g1, @g2) |
+---------------------+---------------------+
|                   1 |                   0 |
+---------------------+---------------------+``````
• Returns 1 or 0 to indicate whether `g1` spatially intersects `g2`.

• Two geometries spatially overlap if they intersect and their intersection results in a geometry of the same dimension but not equal to either of the given geometries.

This function returns 1 or 0 to indicate whether `g1` spatially overlaps `g2`.

• Two geometries spatially touch if their interiors do not intersect, but the boundary of one of the geometries intersects either the boundary or the interior of the other.

This function returns 1 or 0 to indicate whether `g1` spatially touches `g2`.

`ST_Touches()` and `Touches()` are synonyms.

• Returns 1 or 0 to indicate whether `g1` is spatially within `g2`. This tests the opposite relationship as `ST_Contains()`.

• `ST_Touches()` and `Touches()` are synonyms. For more information, see the description of `ST_Touches()`.