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的数组。

示例

  1. nebula> RETURN ST_ASText(ST_Point(1,1));
  2. +--------------------------+
  3. | ST_ASText(ST_Point(1,1)) |
  4. +--------------------------+
  5. | "POINT(1 1)" |
  6. +--------------------------+
  7. nebula> RETURN ST_ASText(ST_GeogFromText("POINT(3 8)"));
  8. +------------------------------------------+
  9. | ST_ASText(ST_GeogFromText("POINT(3 8)")) |
  10. +------------------------------------------+
  11. | "POINT(3 8)" |
  12. +------------------------------------------+
  13. nebula> RETURN ST_ASTEXT(ST_Centroid(ST_GeogFromText("LineString(0 1,1 0)")));
  14. +----------------------------------------------------------------+
  15. | ST_ASTEXT(ST_Centroid(ST_GeogFromText("LineString(0 1,1 0)"))) |
  16. +----------------------------------------------------------------+
  17. | "POINT(0.5000380800773782 0.5000190382261059)" |
  18. +----------------------------------------------------------------+
  19. nebula> RETURN ST_ISValid(ST_GeogFromText("POINT(3 8)"));
  20. +-------------------------------------------+
  21. | ST_ISValid(ST_GeogFromText("POINT(3 8)")) |
  22. +-------------------------------------------+
  23. | true |
  24. +-------------------------------------------+
  25. nebula> RETURN ST_Intersects(ST_GeogFromText("LineString(0 1,1 0)"),ST_GeogFromText("LineString(0 0,1 1)"));
  26. +----------------------------------------------------------------------------------------------+
  27. | ST_Intersects(ST_GeogFromText("LineString(0 1,1 0)"),ST_GeogFromText("LineString(0 0,1 1)")) |
  28. +----------------------------------------------------------------------------------------------+
  29. | true |
  30. +----------------------------------------------------------------------------------------------+
  31. nebula> RETURN ST_Covers(ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"),ST_Point(1,2));
  32. +--------------------------------------------------------------------------------+
  33. | ST_Covers(ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"),ST_Point(1,2)) |
  34. +--------------------------------------------------------------------------------+
  35. | true |
  36. +--------------------------------------------------------------------------------+
  37. nebula> RETURN ST_CoveredBy(ST_Point(1,2),ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"));
  38. +-----------------------------------------------------------------------------------+
  39. | ST_CoveredBy(ST_Point(1,2),ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))")) |
  40. +-----------------------------------------------------------------------------------+
  41. | true |
  42. +-----------------------------------------------------------------------------------+
  43. nebula> RETURN ST_dwithin(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"),20000000000.0);
  44. +---------------------------------------------------------------------------------------+
  45. | ST_dwithin(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"),20000000000) |
  46. +---------------------------------------------------------------------------------------+
  47. | true |
  48. +---------------------------------------------------------------------------------------+
  49. nebula> RETURN ST_Distance(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"));
  50. +----------------------------------------------------------------------------+
  51. | ST_Distance(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)")) |
  52. +----------------------------------------------------------------------------+
  53. | 1568523.0187677438 |
  54. +----------------------------------------------------------------------------+
  55. nebula> RETURN S2_CellIdFromPoint(ST_GeogFromText("Point(1 1)"));
  56. +---------------------------------------------------+
  57. | S2_CellIdFromPoint(ST_GeogFromText("Point(1 1)")) |
  58. +---------------------------------------------------+
  59. | 1153277837650709461 |
  60. +---------------------------------------------------+
  61. nebula> RETURN S2_CoveringCellIds(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))"));
  62. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | S2_CoveringCellIds(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))")) |
  64. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | [1152391494368201343, 1153466862374223872, 1153554823304445952, 1153836298281156608, 1153959443583467520, 1154240918560178176, 1160503736791990272, 1160591697722212352] |
  66. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

最后更新: November 1, 2021