|
| 1 | +# Geography functions |
| 2 | + |
| 3 | +Geography functions are used to generate or perform operations on the value of the geography data type. |
| 4 | + |
| 5 | +For descriptions of the geography data types, see [Geography](../3.data-types/10.geography.md). |
| 6 | + |
| 7 | +## Descriptions |
| 8 | + |
| 9 | +|Function| Description | |
| 10 | +|:----|:----| |
| 11 | +|GEOGRAPHY ST_Point(longitude, latitude) |Creates the geography that contains a point.| |
| 12 | +|GEOGRAPHY ST_GeogFromText(wkt_string) |Returns the geography corresponding to the input WKT string.| |
| 13 | +|STRING ST_ASText(geography) |Returns the WKT string of the input geography.| |
| 14 | +|GEOGRAPHY ST_Centroid(geography) |Returns the centroid of the input geography in the form of the single point geography.| |
| 15 | +|BOOL ST_ISValid(geography) |Returns whether the input geography is valid.| |
| 16 | +|BOOL ST_Intersects(geography_1, geography_2) |Returns whether geography_1 and geography_2 have intersections.| |
| 17 | +|BOOL ST_Covers(geography_1, geography_2) |Returns whether geography_1 completely contains geography_2. If there is no point outside geography_1 in geography_2, return True.| |
| 18 | +|BOOL ST_CoveredBy(geography_1, geography_2) |Returns whether geography_2 completely contains geography_1.If there is no point outside geography_2 in geography_1, return True.| |
| 19 | +|BOOL ST_DWithin(geography_1, geography_2, distance)|If the distance between one point (at least) in geography_1 and one point in geography_2 is less than or equal to the distance specified by the distance parameter (measured by meters), return True.| |
| 20 | +|FLOAT ST_Distance(geography_1, geography_2) |Returns the smallest possible distance (measured by meters) between two non-empty geographies.| |
| 21 | +|INT S2_CellIdFromPoint(point_geography) |Returns the [S2 Cell](https://s2geometry.io/devguide/s2cell_hierarchy) ID that covers the point geography.| |
| 22 | +|ARRAY<INT64> S2_CoveringCellIds(geography) |Returns an array of S2 Cell IDs that cover the input geography.| |
| 23 | + |
| 24 | +## Examples |
| 25 | + |
| 26 | +```ngql |
| 27 | +nebula> RETURN ST_ASText(ST_Point(1,1)) |
| 28 | ++--------------------------+ |
| 29 | +| ST_ASText(ST_Point(1,1)) | |
| 30 | ++--------------------------+ |
| 31 | +| "POINT(1 1)" | |
| 32 | ++--------------------------+ |
| 33 | +
|
| 34 | +nebula> RETURN ST_ASText(ST_GeogFromText("POINT(3 8)")); |
| 35 | ++------------------------------------------+ |
| 36 | +| ST_ASText(ST_GeogFromText("POINT(3 8)")) | |
| 37 | ++------------------------------------------+ |
| 38 | +| "POINT(3 8)" | |
| 39 | ++------------------------------------------+ |
| 40 | +
|
| 41 | +nebula> RETURN ST_ASTEXT(ST_Centroid(ST_GeogFromText("LineString(0 1,1 0)"))); |
| 42 | ++----------------------------------------------------------------+ |
| 43 | +| ST_ASTEXT(ST_Centroid(ST_GeogFromText("LineString(0 1,1 0)"))) | |
| 44 | ++----------------------------------------------------------------+ |
| 45 | +| "POINT(0.5000380800773782 0.5000190382261059)" | |
| 46 | ++----------------------------------------------------------------+ |
| 47 | +
|
| 48 | +nebula> RETURN ST_ISValid(ST_GeogFromText("POINT(3 8)")); |
| 49 | ++-------------------------------------------+ |
| 50 | +| ST_ISValid(ST_GeogFromText("POINT(3 8)")) | |
| 51 | ++-------------------------------------------+ |
| 52 | +| true | |
| 53 | ++-------------------------------------------+ |
| 54 | +
|
| 55 | +nebula> RETURN ST_Intersects(ST_GeogFromText("LineString(0 1,1 0)"),ST_GeogFromText("LineString(0 0,1 1)")); |
| 56 | ++----------------------------------------------------------------------------------------------+ |
| 57 | +| ST_Intersects(ST_GeogFromText("LineString(0 1,1 0)"),ST_GeogFromText("LineString(0 0,1 1)")) | |
| 58 | ++----------------------------------------------------------------------------------------------+ |
| 59 | +| true | |
| 60 | ++----------------------------------------------------------------------------------------------+ |
| 61 | +
|
| 62 | +nebula> RETURN ST_Covers(ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"),ST_Point(1,2)); |
| 63 | ++--------------------------------------------------------------------------------+ |
| 64 | +| ST_Covers(ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))"),ST_Point(1,2)) | |
| 65 | ++--------------------------------------------------------------------------------+ |
| 66 | +| true | |
| 67 | ++--------------------------------------------------------------------------------+ |
| 68 | +
|
| 69 | +nebula> RETURN ST_CoveredBy(ST_Point(1,2),ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))")); |
| 70 | ++-----------------------------------------------------------------------------------+ |
| 71 | +| ST_CoveredBy(ST_Point(1,2),ST_GeogFromText("POLYGON((0 0,10 0,10 10,0 10,0 0))")) | |
| 72 | ++-----------------------------------------------------------------------------------+ |
| 73 | +| true | |
| 74 | ++-----------------------------------------------------------------------------------+ |
| 75 | +
|
| 76 | +nebula> RETURN ST_dwithin(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"),20000000000.0); |
| 77 | ++---------------------------------------------------------------------------------------+ |
| 78 | +| ST_dwithin(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)"),20000000000) | |
| 79 | ++---------------------------------------------------------------------------------------+ |
| 80 | +| true | |
| 81 | ++---------------------------------------------------------------------------------------+ |
| 82 | +
|
| 83 | +nebula> RETURN ST_Distance(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)")); |
| 84 | ++----------------------------------------------------------------------------+ |
| 85 | +| ST_Distance(ST_GeogFromText("Point(0 0)"),ST_GeogFromText("Point(10 10)")) | |
| 86 | ++----------------------------------------------------------------------------+ |
| 87 | +| 1568523.0187677438 | |
| 88 | ++----------------------------------------------------------------------------+ |
| 89 | +
|
| 90 | +nebula> RETURN S2_CellIdFromPoint(ST_GeogFromText("Point(1 1)")); |
| 91 | ++---------------------------------------------------+ |
| 92 | +| S2_CellIdFromPoint(ST_GeogFromText("Point(1 1)")) | |
| 93 | ++---------------------------------------------------+ |
| 94 | +| 1153277837650709461 | |
| 95 | ++---------------------------------------------------+ |
| 96 | +
|
| 97 | +nebula> RETURN S2_CoveringCellIds(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))")); |
| 98 | ++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 99 | +| S2_CoveringCellIds(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))")) | |
| 100 | ++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 101 | +| [1152391494368201343, 1153466862374223872, 1153554823304445952, 1153836298281156608, 1153959443583467520, 1154240918560178176, 1160503736791990272, 1160591697722212352] | |
| 102 | ++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 103 | +``` |
0 commit comments