Documentation Home
MySQL 8.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.2Mb
PDF (A4) - 40.3Mb
Man Pages (TGZ) - 262.0Kb
Man Pages (Zip) - 367.6Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


14.16.7.2 Point Property Functions

APoint consists of X and Y coordinates, which may be obtained using theST_X() andST_Y() functions, respectively. These functions also permit an optional second argument that specifies an X or Y coordinate value, in which case the function result is thePoint object from the first argument with the appropriate coordinate modified to be equal to the second argument.

ForPoint objects that have a geographic spatial reference system (SRS), the longitude and latitude may be obtained using theST_Longitude() andST_Latitude() functions, respectively. These functions also permit an optional second argument that specifies a longitude or latitude value, in which case the function result is thePoint object from the first argument with the longitude or latitude modified to be equal to the second argument.

Unless otherwise specified, functions in this section handle their geometry arguments as follows:

  • If any argument isNULL, the return value isNULL.

  • If any geometry argument is a valid geometry but not aPoint object, anER_UNEXPECTED_GEOMETRY_TYPE error occurs.

  • If any geometry argument is not a syntactically well-formed geometry, anER_GIS_INVALID_DATA error occurs.

  • If any geometry argument is a syntactically well-formed geometry in an undefined spatial reference system (SRS), anER_SRS_NOT_FOUND error occurs.

  • If an X or Y coordinate argument is provided and the value is-inf,+inf, orNaN, anER_DATA_OUT_OF_RANGE error occurs.

  • If a longitude or latitude value is out of range, an error occurs:

    Ranges shown are in degrees. The exact range limits deviate slightly due to floating-point arithmetic.

  • Otherwise, the return value is non-NULL.

These functions are available for obtaining point properties:

  • ST_Latitude(p [,new_latitude_val])

    With a single argument representing a validPoint objectp that has a geographic spatial reference system (SRS),ST_Latitude() returns the latitude value ofp as a double-precision number.

    With the optional second argument representing a valid latitude value,ST_Latitude() returns aPoint object like the first argument with its latitude equal to the second argument.

    ST_Latitude() handles its arguments as described in the introduction to this section, with the addition that if thePoint object is valid but does not have a geographic SRS, anER_SRS_NOT_GEOGRAPHIC error occurs.

    mysql> SET @pt = ST_GeomFromText('POINT(45 90)', 4326);mysql> SELECT ST_Latitude(@pt);+------------------+| ST_Latitude(@pt) |+------------------+|               45 |+------------------+mysql> SELECT ST_AsText(ST_Latitude(@pt, 10));+---------------------------------+| ST_AsText(ST_Latitude(@pt, 10)) |+---------------------------------+| POINT(10 90)                    |+---------------------------------+
  • ST_Longitude(p [,new_longitude_val])

    With a single argument representing a validPoint objectp that has a geographic spatial reference system (SRS),ST_Longitude() returns the longitude value ofp as a double-precision number.

    With the optional second argument representing a valid longitude value,ST_Longitude() returns aPoint object like the first argument with its longitude equal to the second argument.

    ST_Longitude() handles its arguments as described in the introduction to this section, with the addition that if thePoint object is valid but does not have a geographic SRS, anER_SRS_NOT_GEOGRAPHIC error occurs.

    mysql> SET @pt = ST_GeomFromText('POINT(45 90)', 4326);mysql> SELECT ST_Longitude(@pt);+-------------------+| ST_Longitude(@pt) |+-------------------+|                90 |+-------------------+mysql> SELECT ST_AsText(ST_Longitude(@pt, 10));+----------------------------------+| ST_AsText(ST_Longitude(@pt, 10)) |+----------------------------------+| POINT(45 10)                     |+----------------------------------+
  • ST_X(p [,new_x_val])

    With a single argument representing a validPoint objectp,ST_X() returns the X-coordinate value ofp as a double-precision number. The X coordinate is considered to refer to the axis that appears first in thePoint spatial reference system (SRS) definition.

    With the optional second argument,ST_X() returns aPoint object like the first argument with its X coordinate equal to the second argument. If thePoint object has a geographic SRS, the second argument must be in the proper range for longitude or latitude values.

    ST_X() handles its arguments as described in the introduction to this section.

    mysql> SELECT ST_X(Point(56.7, 53.34));+--------------------------+| ST_X(Point(56.7, 53.34)) |+--------------------------+|                     56.7 |+--------------------------+mysql> SELECT ST_AsText(ST_X(Point(56.7, 53.34), 10.5));+-------------------------------------------+| ST_AsText(ST_X(Point(56.7, 53.34), 10.5)) |+-------------------------------------------+| POINT(10.5 53.34)                         |+-------------------------------------------+
  • ST_Y(p [,new_y_val])

    With a single argument representing a validPoint objectp,ST_Y() returns the Y-coordinate value ofp as a double-precision number.The Y coordinate is considered to refer to the axis that appears second in thePoint spatial reference system (SRS) definition.

    With the optional second argument,ST_Y() returns aPoint object like the first argument with its Y coordinate equal to the second argument. If thePoint object has a geographic SRS, the second argument must be in the proper range for longitude or latitude values.

    ST_Y() handles its arguments as described in the introduction to this section.

    mysql> SELECT ST_Y(Point(56.7, 53.34));+--------------------------+| ST_Y(Point(56.7, 53.34)) |+--------------------------+|                    53.34 |+--------------------------+mysql> SELECT ST_AsText(ST_Y(Point(56.7, 53.34), 10.5));+-------------------------------------------+| ST_AsText(ST_Y(Point(56.7, 53.34), 10.5)) |+-------------------------------------------+| POINT(56.7 10.5)                          |+-------------------------------------------+