[TOC] #### 7.2.2.1 ST\_AsText, ST\_AsWKT **函数定义** `VARCHAR ST_AsText(GEOMETRY geo)` 将一个几何图形转化为WKT(Well Known Text)的表示形式。 **示例** `mysql> SELECT ST_AsText(ST_Point(24.7, 56.7));` `+---------------------------------+` `| st_astext(st_point(24.7, 56.7)) |` `+---------------------------------+` `| POINT (24.7 56.7)               |` `+---------------------------------+` **关键字** `ST_ASTEXT, ST_ASWKT, ST, ASTEXT, ASWKT` <br> #### 7.2.2.2 ST\_Circle **函数定义** `GEOMETRY ST_Circle(DOUBLE center_lng, DOUBLE center_lat, DOUBLE radius)` 生成几何图形:圆。其中center\_lng表示的圆心的经度,center\_lat表示的是圆心的纬度,radius表示的是圆的半径,单位是米,最大支持9999999。 **示例** `mysql> SELECT ST_AsText(ST_Circle(111, 64, 10000));` `+--------------------------------------------+` `| st_astext(st_circle(111.0, 64.0, 10000.0)) |` `+--------------------------------------------+` `| CIRCLE ((111 64), 10000)                   |` `+--------------------------------------------+` **关键字** `ST_CIRCLE, ST, CIRCLE` <br> #### 7.2.2.3 ST\_Contains **函数定义** `BOOL ST_Contains(GEOMETRY shape1, GEOMETRY shape2)` 判断几何图形shape1是否完全能够包含几何图形shape2。 **示例** `mysql> SELECT ST_Contains(ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"), ST_Point(5, 5));` `+----------------------------------------------------------------------------------------+` `| st_contains(st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'), st_point(5.0, 5.0)) |` `+----------------------------------------------------------------------------------------+` `|                                                                                      1 |` `+----------------------------------------------------------------------------------------+` `mysql> SELECT ST_Contains(ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"), ST_Point(50, 50));` `+------------------------------------------------------------------------------------------+` `| st_contains(st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'), st_point(50.0, 50.0)) |` `+------------------------------------------------------------------------------------------+` `|                                                                                        0 |` `+----------------` **关键字** `ST_CONTAINS, ST, CONTAINS` <br> #### 7.2.2.4 ST\_Distance\_Sphere **函数定义** `DOUBLE ST_Distance_Sphere(DOUBLE x_lng, DOUBLE x_lat, DOUBLE y_lng, DOUBLE x_lat)` 计算地球两点之间的球面距离,单位为米。传入的参数分别为X点的经度,X点的纬度,Y点的经度,Y点的纬度。 **示例** `mysql> select st_distance_sphere(116.35620117, 39.939093, 116.4274406433, 39.9020987219);` `+----------------------------------------------------------------------------+` `| st_distance_sphere(116.35620117, 39.939093, 116.4274406433, 39.9020987219) |` `+----------------------------------------------------------------------------+` `| 7336.9135549995917 |` `+----------------------------------------------------------------------------+` **关键字** `ST_DISTANCE_SPHERE, ST, DISTANCE, SPHERE` <br> #### 7.2.2.5 ST\_GeometryFromText, ST\_GeomFromText **函数定义** `GEOMETRY ST_GeometryFromText(VARCHAR wkt)` 将WKT(Well Known Text)格式的几何对象转化为对应的内存对象。 **示例** `mysql> SELECT ST_AsText(ST_GeometryFromText("LINESTRING (1 1, 2 2)"));` `+---------------------------------------------------------+` `| st_astext(st_geometryfromtext('LINESTRING (1 1, 2 2)')) |` `+---------------------------------------------------------+` `| LINESTRING (1 1, 2 2)                                   |` `+---------------------------------------------------------+` **关键字** `ST_GEOMETRYFROMTEXT, ST_GEOMFROMTEXT, ST, GEOMETRYFROMTEXT, GEOMFROMTEXT` <br> #### 7.2.2.6 ST\_LineFromText, ST\_LineStringFromText **函数定义** `GEOMETRY ST_LineFromText(VARCHAR wkt)` 将WKT(Well Known Text)格式的几何对象转化为Line类型的内存对象。 **示例** `mysql> SELECT ST_AsText(ST_LineFromText("LINESTRING (1 1, 2 2)"));` `+---------------------------------------------------------+` `| st_astext(st_geometryfromtext('LINESTRING (1 1, 2 2)')) |` `+---------------------------------------------------------+` `| LINESTRING (1 1, 2 2)                                   |` `+---------------------------------------------------------+` **关键字** `ST_LINEFROMTEXT, ST_LINESTRINGFROMTEXT, ST, LINEFROMTEXT, LINESTRINGFROMTEXT` <br> #### 7.2.2.7 ST\_Point **函数定义** `POINT ST_Point(DOUBLE x, DOUBLE y)` 通过给定的X坐标值,Y坐标值返回对应的Point。 当前这个值只是在球面集合上有意义,X/Y对应的是经度/纬度(longitude/latitude)。 **示例** `mysql> SELECT ST_AsText(ST_Point(24.7, 56.7));` `+---------------------------------+` `| st_astext(st_point(24.7, 56.7)) |` `+---------------------------------+` `| POINT (24.7 56.7)               |` `+---------------------------------+` **关键字** `ST_POINT, ST, POINT` <br> #### 7.2.2.8 ST\_Polygon,ST\_PolyFromText,ST\_PolygonFromText **函数定义** `GEOMETRY ST_Polygon(VARCHAR wkt)` 将WKT(Well Known Text)格式的对象转化为对应的多边形内存对象。 **示例** `mysql> SELECT ST_AsText(ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"));` `+------------------------------------------------------------------+` `| st_astext(st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) |` `+------------------------------------------------------------------+` `| POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))                          |` `+------------------------------------------------------------------+` **关键字** `ST_POLYGON, ST_POLYFROMTEXT, ST_POLYGONFROMTEXT, ST, POLYGON, POLYFROMTEXT, POLYGONFROMTEXT` <br> #### 7.2.2.9 ST\_X **函数定义** `DOUBLE ST_X(POINT point)` 当point是一个合法的POINT类型时,返回对应的X坐标值。 **示例** `mysql> SELECT ST_X(ST_Point(24.7, 56.7));` `+----------------------------+` `| st_x(st_point(24.7, 56.7)) |` `+----------------------------+` `| 24.7 |` `+----------------------------+` **关键字** `ST_X, ST, X` <br> #### 7.2.2.10 ST\_Y **函数定义** `DOUBLE ST_Y(POINT point)` 当point是一个合法的POINT类型时,返回对应的Y坐标值。 **示例** `mysql> SELECT ST_Y(ST_Point(24.7, 56.7));` `+----------------------------+` `| st_y(st_point(24.7, 56.7)) |` `+----------------------------+` `| 56.7 |` `+----------------------------+` **关键字** `ST_Y, ST, Y`