Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 35.1Mb
PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

12.16.9.1 Spatial Relation Functions That Use Object Shapes

The OpenGIS specification defines the following functions to test the relationship between two geometry valuesg1 andg2, using precise object shapes. The return values 1 and 0 indicate true and false, respectively, except forST_Distance() andDistance(), which return distance values.

These functions support all argument type combinations except those that are inapplicable according to the Open Geospatial Consortium specification.

  • Crosses(g1,g2)

    ST_Crosses() andCrosses() are synonyms. For more information, see the description ofST_Crosses().

    Crosses() is deprecated; expect it to be removed in a future MySQL release. UseST_Crosses() instead.

  • Distance(g1,g2)

    ST_Distance() andDistance() are synonyms. For more information, see the description ofST_Distance().

    Distance() is deprecated; expect it to be removed in a future MySQL release. UseST_Distance() instead.

  • ST_Contains(g1,g2)

    Returns 1 or 0 to indicate whetherg1 completely containsg2. This tests the opposite relationship asST_Within().

  • ST_Crosses(g1,g2)

    The termspatially 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 whetherg1 spatially crossesg2. Ifg1 is aPolygon or aMultiPolygon, or ifg2 is aPoint or aMultiPoint, the return value isNULL.

    This function returns 0 if called with an inapplicable geometry argument type combination. For example, it returns 0 if the first argument is aPolygon orMultiPolygon and/or the second argument is aPoint orMultiPoint.

    Returns 1 ifg1 spatially crossesg2. ReturnsNULL ifg1 is aPolygon or aMultiPolygon, or ifg2 is aPoint or aMultiPoint. Otherwise, returns 0.

    This function returns 0 if called with an inapplicable geometry argument type combination. For example, it returns 0 if the first argument is aPolygon orMultiPolygon and/or the second argument is aPoint orMultiPoint.

    ST_Crosses() andCrosses() are synonyms.

  • ST_Disjoint(g1,g2)

    Returns 1 or 0 to indicate whetherg1 is spatially disjoint from (does not intersect)g2.

  • ST_Distance(g1,g2)

    Returns the distance betweeng1 andg2. If either argument isNULL or an empty geometry, the return value isNULL.

    This function processes geometry collections by returning the shortest distance among all combinations of the components of the two geometry arguments.

    If an intermediate or final result produces NaN or a negative number, anER_GIS_INVALID_DATA error occurs.

    mysql> SET @g1 = Point(1,1);mysql> SET @g2 = Point(2,2);mysql> SELECT ST_Distance(@g1, @g2);+-----------------------+| ST_Distance(@g1, @g2) |+-----------------------+|    1.4142135623730951 |+-----------------------+

    ST_Distance() andDistance() are synonyms.

  • ST_Equals(g1,g2)

    Returns 1 or 0 to indicate whetherg1 is spatially equal tog2.

    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 |+---------------------+---------------------+
  • ST_Intersects(g1,g2)

    Returns 1 or 0 to indicate whetherg1 spatially intersectsg2.

  • ST_Overlaps(g1,g2)

    Two geometriesspatially 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 whetherg1 spatially overlapsg2.

    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 aPoint.

  • ST_Touches(g1,g2)

    Two geometriesspatially 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 whetherg1 spatially touchesg2.

    This function returns 0 if called with an inapplicable geometry argument type combination. For example, it returns 0 if either of the arguments is aPoint orMultiPoint.

    ST_Touches() andTouches() are synonyms.

  • ST_Within(g1,g2)

    Returns 1 or 0 to indicate whetherg1 is spatially withing2. This tests the opposite relationship asST_Contains().

  • Touches(g1,g2)

    ST_Touches() andTouches() are synonyms. For more information, see the description ofST_Touches().

    Touches() is deprecated; expect it to be removed in a future MySQL release. UseST_Touches() instead.