Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 33.7Mb
PDF (A4) - 33.7Mb
PDF (RPM) - 31.7Mb
HTML Download (TGZ) - 8.1Mb
HTML Download (Zip) - 8.1Mb
HTML Download (RPM) - 6.9Mb
Man Pages (TGZ) - 145.6Kb
Man Pages (Zip) - 206.4Kb
Info (Gzip) - 3.1Mb
Info (Zip) - 3.1Mb


MySQL 8.0 Reference Manual  /  ...  /  General Geometry Property Functions

Pre-General Availability Draft: 2017-10-20

12.15.7.1 General Geometry Property Functions

The functions listed in this section do not restrict their argument and accept a geometry value of any type.

  • ST_Dimension(g)

    Returns the inherent dimension of the geometry value g, or NULL if the argument is NULL. The dimension can be −1, 0, 1, or 2. The meaning of these values is given in Section 11.5.2.2, “Geometry Class”.

    mysql> SELECT ST_Dimension(ST_GeomFromText('LineString(1 1,2 2)'));
    +------------------------------------------------------+
    | ST_Dimension(ST_GeomFromText('LineString(1 1,2 2)')) |
    +------------------------------------------------------+
    |                                                    1 |
    +------------------------------------------------------+
  • ST_Envelope(g)

    Returns the minimum bounding rectangle (MBR) for the geometry value g, or NULL if the argument is NULL. The result is returned as a Polygon value that is defined by the corner points of the bounding box:

    POLYGON((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
    mysql> SELECT ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,2 2)')));
    +----------------------------------------------------------------+
    | ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,2 2)'))) |
    +----------------------------------------------------------------+
    | POLYGON((1 1,2 1,2 2,1 2,1 1))                                 |
    +----------------------------------------------------------------+

    If the argument is a point or a vertical or horizontal line segment, ST_Envelope() returns the point or the line segment as its MBR rather than returning an invalid polygon:

    mysql> SELECT ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,1 2)')));
    +----------------------------------------------------------------+
    | ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,1 2)'))) |
    +----------------------------------------------------------------+
    | LINESTRING(1 1,1 2)                                            |
    +----------------------------------------------------------------+
  • ST_GeometryType(g)

    Returns a binary string indicating the name of the geometry type of which the geometry instance g is a member, or NULL if the argument is NULL. The name corresponds to one of the instantiable Geometry subclasses.

    mysql> SELECT ST_GeometryType(ST_GeomFromText('POINT(1 1)'));
    +------------------------------------------------+
    | ST_GeometryType(ST_GeomFromText('POINT(1 1)')) |
    +------------------------------------------------+
    | POINT                                          |
    +------------------------------------------------+
  • ST_IsEmpty(g)

    This function is a placeholder that returns 0 for any valid geometry value, 1 for any invalid geometry value, or NULL if the argument is NULL.

    MySQL does not support GIS EMPTY values such as POINT EMPTY.

  • ST_IsSimple(g)

    Returns 1 if the geometry value g has no anomalous geometric points, such as self-intersection or self-tangency. ST_IsSimple() returns 0 if the argument is not simple, and NULL if the argument is NULL.

    The description of each instantiable geometric class given earlier in the chapter includes the specific conditions that cause an instance of that class to be classified as not simple. (See Section 11.5.2.1, “The Geometry Class Hierarchy”.)

  • ST_SRID(g[, new_srid_val])

    With a single argument representing a valid geometry object g, ST_SRID() returns an integer indicating the spatial reference system (SRS) ID associated with g.

    If the geometry argument is NULL, the return value is NULL. If the argument is not a syntactically well-formed geometry, an ER_GIS_INVALID_DATA error occurs.

    If the optional second argument representing a valid SRID value is given, ST_SRID() returns an object with the same type as its first argument, having an SRID value equal to the second argument, or NULL if either argument is NULL. These conditions apply when the second argument is given:

    • Error handling for the first argument is as for the single-argument syntax, as described previously.

    • If the SRID value in the second argument is not within the range of a 32-bit unsigned integer, an ER_DATA_OUT_OF_RANGE error occurs.

    • If the second argument does not refer to a known SRS (has an unknown SRID value), an ER_SRS_NOT_FOUND error occurs.

    mysql> SET @g = ST_GeomFromText('LineString(1 1,2 2)', 0);
    mysql> SELECT ST_SRID(@g);
    +-------------+
    | ST_SRID(@g) |
    +-------------+
    |           0 |
    +-------------+
    mysql> SET @g2 = ST_SRID(@g, 4326);
    mysql> SELECT ST_SRID(@g2);
    +--------------+
    | ST_SRID(@g2) |
    +--------------+
    |         4326 |
    +--------------+

    It is possible to create a geometry in a particular SRID by passing to ST_SRID() the result of one of the MySQL-specific functions for creating spatial values, along with an SRID value. For example:

    SET @g1 = ST_SRID(Point(1, 1), 4326);

    However, that method creates the geometry in SRID 0, then casts it to SRID 4326 (WGS 84). A preferable alternative is to create the geometry with the correct spatial reference system (SRS) to begin with. For example:

    SET @g1 = ST_PointFromText('POINT(1 1)', 4326);
    SET @g1 = ST_GeomFromText('POINT(1 1)', 4326);

    The two-argument form of ST_SRID() is useful for tasks such as correcting or changing the SRS of geometries that have an incorrect SRID.


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