共用方式為


h3_distance 函式

適用於:檢查標示為是 Databricks SQL 檢查標示為是 Databricks Runtime 11.3 LTS 和更新版本

傳回兩個輸入 H3 單元格標識碼的網格線距離。

語法

h3_distance ( h3CellId1Expr, h3CellId2Expr )

引數

  • h3CellId1Expr:BIGINT 運算式,或代表 H3 單元格標識符的十六進位 STRING 運算式。
  • h3CellId2Expr:BIGINT 運算式,或代表 H3 單元格標識符的十六進位 STRING 運算式。

傳回

BIGINT 值,這是兩個輸入 H3 單元格的方格距離,預期具有相同解析度。

如果任一輸入表達式為 NULL,此函式會傳回 NULL。 函式會針對輸入自變數是否為有效的 H3 單元格標識碼執行部分驗證。 有效 H3 識別符的必要條件,但沒有足夠的條件是其值介於和0x08ff3b6db6db6db6之間0x08001fffffffffff。 如果兩個輸入單元格標識碼中有任何一個不是有效的數據格標識碼,則函式的行為是未定義的。

錯誤狀況

  • 如果 h3CellId1Exprh3CellId2Expr 是無法轉換成 BIGINT 的 STRING,或對應至小於 0x08001fffffffffff 或大於 0x08ff3b6db6db6db6的 BIGINT 值,則函式會 傳回H3_INVALID_CELL_ID
  • 如果未定義網格線距離,函式會 傳回H3_UNDEFINED_GRID_DISTANCE。 網格線距離可能因為下列任何原因而無法定義:
    • 兩個輸入 H3 儲存格的解析度不同。
    • 這兩個輸入 H3 單元格中的任何一個是五角大樓單元格。
    • 這兩個 H3 儲存格由五角大樓單元格分隔。
    • 這兩個H3細胞彼此相距太遠。

範例

-- Example where the two arguments are BIGINTs representing H3 cells.
> SELECT h3_distance(599686030622195711, 599686015589810175);
 2

-- Example where the two arguments are hexadecimal STRINGs representing H3 cells.
> SELECT h3_distance('85283447fffffff', '8528340ffffffff')
 2

-- Example of two cells that too far apart from each other.
> SELECT h3_distance(h3_longlatash3(-120, 45, 13), h3_longlatash3(120, 45, 13))
  [H3_UNDEFINED_GRID_DISTANCE] H3 grid distance between 635723017894513407 and 635869868887430591 is undefined

-- Example of two cells with different resolutions.
> SELECT h3_distance(h3_longlatash3(120, 45, 13), h3_longlatash3(120, 45, 12));
  [H3_UNDEFINED_GRID_DISTANCE] H3 grid distance between 635869868887430591 and 631366269260060159 is undefined

-- First cell ID is a pentagon.
> SELECT h3_distance(590112357393367039, 590678880759578623)
  [H3_UNDEFINED_GRID_DISTANCE] H3 grid distance between 590112357393367039 and 590678880759578623 is undefined

-- Distance between two hexagons separated by a pentagon.
> SELECT h3_distance(590112494832320511, 590112632271273983)
  [H3_UNDEFINED_GRID_DISTANCE] H3 grid distance between 590112494832320511 and 590112632271273983 is undefined