Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 35.6Mb
PDF (A4) - 35.6Mb
PDF (RPM) - 34.7Mb
EPUB - 8.7Mb
HTML Download (TGZ) - 8.5Mb
HTML Download (Zip) - 8.5Mb
HTML Download (RPM) - 7.3Mb
Eclipse Doc Plugin (TGZ) - 9.3Mb
Eclipse Doc Plugin (Zip) - 11.5Mb
Man Pages (TGZ) - 203.5Kb
Man Pages (Zip) - 310.2Kb
Info (Gzip) - 3.3Mb
Info (Zip) - 3.3Mb
Excerpts from this Manual

13.15.9.1 Spatial Relation Functions That Use Object Shapes

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, except for ST_Distance() and Distance(), which return distance values.

As of MySQL 5.7.5, these functions support all 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.

  • Crosses(g1,g2)

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

    Crosses() is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. Use ST_Crosses() instead.

  • Distance(g1,g2)

    ST_Distance() and Distance() are synonyms. For more information, see the description of ST_Distance().

    Distance() was added in MySQL 5.7.5.

    Distance() is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. Use ST_Distance() instead.

  • ST_Contains(g1,g2)

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

  • ST_Crosses(g1,g2)

    Returns 1 if g1 spatially crosses g2. Returns NULL if g1 is a Polygon or a MultiPolygon, or if g2 is a 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

    ST_Crosses() and Crosses() are synonyms.

  • ST_Disjoint(g1,g2)

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

  • ST_Distance(g1,g2)

    Returns the distance between g1 and 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> SET @g1 = POINT(1,1), @g2 = POINT(2,2);
    mysql> SELECT ST_Distance(@g1, @g2);
    +-----------------------+
    | ST_Distance(@g1, @g2) |
    +-----------------------+
    |    1.4142135623730951 |
    +-----------------------+
    

    ST_Distance() and Distance() are synonyms.

  • ST_Equals(g1,g2)

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

    Returns 1 or 0 to indicate whether g1 spatially intersects g2.

  • ST_Overlaps(g1,g2)

    Returns 1 or 0 to indicate whether g1 spatially overlaps g2. The term 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.

  • ST_Touches(g1,g2)

    Returns 1 or 0 to indicate whether g1 spatially touches g2. Two geometries 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.

    ST_Touches() and Touches() are synonyms.

  • ST_Within(g1,g2)

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

  • Touches(g1,g2)

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

    Touches() is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. Use ST_Touches() instead.


User Comments
Sign Up Login You must be logged in to post a comment.