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

MySQL 5.5 Reference Manual :: 12 Functions and Operators :: 12.17 Spatial Extensions :: 12.17.5 Spatial Analysis Functions :: 12.17.5.4 Functions for Testing Spatial Relations Between Geometric Objects

- 12.17.5 Spatial Analysis Functions
- 12.17.5.1 Geometry Format Conversion Functions
- 12.17.5.2 Geometry Property Functions
- 12.17.5.3 Functions That Create New Geometries from Existing Ones
- 12.17.5.4 Functions for Testing Spatial Relations Between Geometric Objects

The functions described in these sections take two geometries as input parameters and return a qualitative or quantitative relation between them.

MySQL provides several functions that test relations between
minimal bounding rectangles of two geometries
`g1`

and `g2`

. The return
values 1 and 0 indicate true and false, respectively.

Returns 1 or 0 to indicate whether the Minimum Bounding Rectangle of

contains the Minimum Bounding Rectangle of`g1`

. This tests the opposite relationship as`g2`

`MBRWithin()`

.mysql>

mysql>`SET @g1 = GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');`

mysql>`SET @g2 = GeomFromText('Point(1 1)');`

----------------------+----------------------+ | MBRContains(@g1,@g2) | MBRContains(@g2,@g1) | +----------------------+----------------------+ | 1 | 0 | +----------------------+----------------------+`SELECT MBRContains(@g1,@g2), MBRContains(@g2,@g1);`

Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries

and`g1`

are disjoint (do not intersect).`g2`

Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries

and`g1`

are the same.`g2`

Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries

and`g1`

intersect.`g2`

Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries

and`g1`

overlap. 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.Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries

and`g1`

touch. 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.Returns 1 or 0 to indicate whether the Minimum Bounding Rectangle of

is within the Minimum Bounding Rectangle of`g1`

. This tests the opposite relationship as`g2`

`MBRContains()`

.mysql>

mysql>`SET @g1 = GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');`

mysql>`SET @g2 = GeomFromText('Polygon((0 0,0 5,5 5,5 0,0 0))');`

+--------------------+--------------------+ | MBRWithin(@g1,@g2) | MBRWithin(@g2,@g1) | +--------------------+--------------------+ | 1 | 0 | +--------------------+--------------------+`SELECT MBRWithin(@g1,@g2), MBRWithin(@g2,@g1);`

The OpenGIS specification defines the following functions.
They test the relationship between two geometry values
`g1`

and `g2`

.

The return values 1 and 0 indicate true and false, respectively.

Note

Currently, MySQL does not implement these functions according to the specification. Those that are implemented return the same result as the corresponding MBR-based functions.

Returns 1 or 0 to indicate whether

completely contains`g1`

. This tests the opposite relationship as`g2`

`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.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 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.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.Returns 1 or 0 to indicate whether

is spatially within`g1`

. This tests the opposite relationship as`g2`

`Contains()`

.

Copyright © 1997, 2014, Oracle and/or its affiliates. All rights reserved. Legal Notices

## User Comments