Skip navigation links
**Section Navigation** [Toggle]

MySQL 5.7 Reference Manual :: 12 Functions and Operators :: 12.15 Spatial Analysis Functions :: 12.15.9 Functions That Test Spatial Relations Between Geometry Objects :: 12.15.9.1 Spatial Relation Functions That Use Object Shapes

- 12.15.9 Functions That Test Spatial Relations Between Geometry Objects
- 12.15.9.1 Spatial Relation Functions That Use Object Shapes
- 12.15.9.2 Spatial Relation Functions That Use Minimum Bounding Rectangles (MBRs)
- 12.15.9.3 MySQL-Specific Spatial Relation Functions That Use Minimum Bounding Rectangles (MBRs)

The OpenGIS specification defines the following functions. They
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.

As of MySQL 5.7.5, these functions support argument type
combinations except those that are inapplicable according to the
Open Geospatial Consortium specification. They return false if
called with an inapplicable geometry argument type combination.
For example, `ST_Overlaps()`

returns false if called with geometries of different dimensions.

Returns 1 or 0 to indicate whether

completely contains`g1`

. This tests the opposite relationship as`g2`

`ST_Within()`

.Returns 1 if

spatially crosses`g1`

. Returns`g2`

`NULL`

if`g1`

is a`Polygon`

or a`MultiPolygon`

, or ifis a`g2`

`Point`

or a`MultiPoint`

. Otherwise, returns 0.As of MySQL 5.7.5, this function returns 0 if called with an inapplicable geometry argument type combination. For example, it returns 0 if the first argument is a

`Polygon`

or`MultiPolygon`

and/or the second argument is a`Point`

or`MultiPoint`

.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

Returns 1 or 0 to indicate whether

is spatially disjoint from (does not intersect)`g1`

.`g2`

Returns the distance between

and`g1`

.`g2`

As of MySQL 5.7.5, this function processes geometry collections by returning the shortest distance among all combinations of the components of the two geometry arguments. If either argument is an empty geometry collection, the return value is

`NULL`

.As of MySQL 5.7.6, if an intermediate or final result produces NaN or a negative number, this function produces a

`ER_GIS_INVALID_DATA`

error.mysql>

mysql>`SET @g1 = POINT(1,1), @g2 = POINT(2,2);`

+-----------------------+ | ST_Distance(@g1, @g2) | +-----------------------+ | 1.4142135623730951 | +-----------------------+`SELECT ST_Distance(@g1, @g2);`

`ST_Distance()`

and`Distance()`

are synonyms.Returns 1 or 0 to indicate whether

is spatially equal to`g1`

.`g2`

Returns 1 or 0 to indicate whether

spatially intersects`g1`

.`g2`

Returns 1 or 0 to indicate whether

spatially overlaps`g1`

. The term`g2`

*spatially overlaps*is used if two geometries intersect and their intersection results in a geometry of the same dimension but not equal to either of the given geometries.As of MySQL 5.7.5, this function returns 0 if called with an inapplicable geometry argument type combination. For example, it returns 0 if called with geometries of different dimensions or any argument is a

`Point`

.Returns 1 or 0 to indicate whether

spatially touches`g1`

. Two geometries`g2`

*spatially touch*if the interiors of the geometries do not intersect, but the boundary of one of the geometries intersects either the boundary or the interior of the other.As of MySQL 5.7.5, this function returns 0 if called with an inapplicable geometry argument type combination. For example, it returns 0 if either of the arguments is a

`Point`

or`MultiPoint`

.Returns 1 or 0 to indicate whether

is spatially within`g1`

. This tests the opposite relationship as`g2`

`ST_Contains()`

.

## User Comments