跳转至

geo函数Graph

geo函数用于生成地理位置(GEOGRAPHY)数据类型的值或对其执行操作。

关于地理位置数据类型说明请参见Graph。

函数说明Graph

函数 返回类型 说明
ST_Point(longitude, latitude) GEOGRAPHY 创建包含一个点的地理位置。
ST_GeogFromText(wkt_string) GEOGRAPHY 返回与传入的WKT字符串形式相对应的GEOGRAPHY。
ST_ASText(geography) STRING 返回传入的GEOGRAPHY的WKT字符串形式。
ST_Centroid(geography) GEOGRAPHY 以单点GEOGRAPHY的形式返回传入的GEOGRAPHY的形心。
ST_ISValid(geography) BOOL 返回传入的GEOGRAPHY是否有效。
ST_Intersects(geography_1, geography_2) BOOL 返回传入的两个GEOGRAPHY是否有交集。
ST_Covers(geography_1, geography_2) BOOL 返回geography_1是否完全包含geography_2。如果geography_2中没有位于geography_1外部的点,返回True。
ST_CoveredBy(geography_1, geography_2) BOOL 返回geography_2是否完全包含geography_1。如果geography_1中没有位于geography_2外部的点,返回True。
ST_DWithin(geography_1, geography_2, distance) BOOL 如果geography_1中至少有一个点与geography_2中的一个点的距离小于或等于distance参数(以米为单位)指定的距离,则返回True。
ST_Distance(geography_1, geography_2) FLOAT 返回两个非空GEOGRAPHY之间的最短距离(以米为单位)。
S2_CellIdFromPoint(point_geography) INT 返回覆盖点GEOGRAPHY的GraphID。
S2_CoveringCellIds(geography) ARRAY<INT64> 返回覆盖传入的GEOGRAPHY的S2单元ID的数组。

示例Graph

nebula> RETURN ST_ASText(ST_Point(1,1));
+--------------------------+
| ST_ASText(ST_Point(1,1)) |
+--------------------------+
| "POINT(1 1)"             |
+--------------------------+

nebula> RETURN ST_ASText(ST_GeogFromText("POINT(3 8)"));
+------------------------------------------+
| ST_ASText(ST_GeogFromText("POINT(3 8)")) |
+------------------------------------------+
| "POINT(3 8)"                             |
+------------------------------------------+

nebula> RETURN ST_ASTEXT(ST_Centroid(ST_GeogFromText("LineString(0 1,1 0)")));
+----------------------------------------------------------------+
| ST_ASTEXT(ST_Centroid(ST_GeogFromText("LineString(0 1,1 0)"))) |
+----------------------------------------------------------------+
| "POINT(0.5000380800773782 0.5000190382261059)"                 |
+----------------------------------------------------------------+

nebula> RETURN ST_ISValid(ST_GeogFromText("POINT(3 8)"));
+-------------------------------------------+
| ST_ISValid(ST_GeogFromText("POINT(3 8)")) |
+-------------------------------------------+
| true                                      |
+-------------------------------------------+

nebula> RETURN ST_Intersects(ST_GeogFromText("LineString(0 1,1 0)"),ST_GeogFromText("LineString(0 0,1 1)"));
+----------------------------------------------------------------------------------------------+
| ST_Intersects(ST_GeogFromText("LineString(0 1,1 0)"),ST_GeogFromText("LineString(0 0,1 1)")) |
+----------------------------------------------------------------------------------------------+
| true                                                                                         |
+----------------------------------------------------------------------------------------------+

nebula> RETURN ST_Covers(ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"),ST_Point(1,2));
+--------------------------------------------------------------------------------+
| ST_Covers(ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"),ST_Point(1,2)) |
+--------------------------------------------------------------------------------+
| true                                                                           |
+--------------------------------------------------------------------------------+

nebula> RETURN ST_CoveredBy(ST_Point(1,2),ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"));
+-----------------------------------------------------------------------------------+
| ST_CoveredBy(ST_Point(1,2),ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))")) |
+-----------------------------------------------------------------------------------+
| true                                                                              |
+-----------------------------------------------------------------------------------+

nebula> RETURN ST_dwithin(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"),20000000000.0);
+---------------------------------------------------------------------------------------+
| ST_dwithin(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"),20000000000) |
+---------------------------------------------------------------------------------------+
| true                                                                                  |
+---------------------------------------------------------------------------------------+

nebula> RETURN ST_Distance(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"));
+----------------------------------------------------------------------------+
| ST_Distance(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)")) |
+----------------------------------------------------------------------------+
| 1568523.0187677438                                                         |
+----------------------------------------------------------------------------+

nebula> RETURN S2_CellIdFromPoint(ST_GeogFromText("Point(1 1)"));
+---------------------------------------------------+
| S2_CellIdFromPoint(ST_GeogFromText("Point(1 1)")) |
+---------------------------------------------------+
| 1153277837650709461                               |
+---------------------------------------------------+

nebula> RETURN S2_CoveringCellIds(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))"));
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| S2_CoveringCellIds(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))"))                                                                                                     |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [1152391494368201343, 1153466862374223872, 1153554823304445952, 1153836298281156608, 1153959443583467520, 1154240918560178176, 1160503736791990272, 1160591697722212352] |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

最后更新: November 1, 2021
Back to top