MySQL 5.5 Reference Manual  /  ...  /  Spatial Relation Functions That Use Minimum Bounding Rectangles

#### 12.16.9.2 Spatial Relation Functions That Use Minimum Bounding Rectangles

MySQL provides several MySQL-specific functions that test the relationship between minimum bounding rectangles (MBRs) of two geometries `g1` and `g2`. The return values 1 and 0 indicate true and false, respectively.

A corresponding set of MBR functions defined according to the OpenGIS specification is described later in this section.

• Returns 1 or 0 to indicate whether the minimum bounding rectangle of `g1` contains the minimum bounding rectangle of `g2`. This tests the opposite relationship as `MBRWithin()`.

``````mysql> SET @g1 = GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
mysql> SET @g2 = GeomFromText('Point(1 1)');
mysql> SELECT MBRContains(@g1,@g2), MBRWithin(@g2,@g1);
+----------------------+--------------------+
| MBRContains(@g1,@g2) | MBRWithin(@g2,@g1) |
+----------------------+--------------------+
|                    1 |                  1 |
+----------------------+--------------------+``````
• Returns 1 or 0 to indicate whether the minimum bounding rectangles of the two geometries `g1` and `g2` are disjoint (do not intersect).

• Returns 1 or 0 to indicate whether the minimum bounding rectangles of the two geometries `g1` and `g2` are the same.

• Returns 1 or 0 to indicate whether the minimum bounding rectangles of the two geometries `g1` and `g2` intersect.

• 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 the minimum bounding rectangles of the two geometries `g1` and `g2` overlap.

• 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 the minimum bounding rectangles of the two geometries `g1` and `g2` touch.

• Returns 1 or 0 to indicate whether the minimum bounding rectangle of `g1` is within the minimum bounding rectangle of `g2`. This tests the opposite relationship as `MBRContains()`.

``````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))');
mysql> SELECT MBRWithin(@g1,@g2), MBRWithin(@g2,@g1);
+--------------------+--------------------+
| MBRWithin(@g1,@g2) | MBRWithin(@g2,@g1) |
+--------------------+--------------------+
|                  1 |                  0 |
+--------------------+--------------------+``````

The OpenGIS specification defines the following functions that test the relationship between two geometry values `g1` and `g2`. The MySQL implementation uses minimum bounding rectangles, so these functions return the same result as the corresponding MBR-based functions described earlier in this section. The return values 1 and 0 indicate true and false, respectively.

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

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

• Returns 1 or 0 to indicate whether `g1` is spatially equal to `g2`.

• 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`.

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