跳到主要内容
版本:3.12.0

geo 函数

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

关于地理空间数据类型说明请参见地理空间

函数说明

函数返回类型说明
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 的 S2 单元ID。
S2_CoveringCellIds(geography)ARRAY<INT64>返回覆盖传入的 GEOGRAPHY 的 S2 单元 ID 的数组。

示例

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)")) |
+----------------------------------------------------------------------------+
| 1.5685230187677438e+06 |
+----------------------------------------------------------------------------+

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] |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+