Categories:

Geospatial functions

H3_TRY_GRID_DISTANCE

A special version of H3_GRID_DISTANCE that returns NULL if an error occurs when it attempts to return the distance between two H3 cells.

语法

H3_TRY_GRID_DISTANCE( <cell_id_1> , <cell_id_2> )

实参

cell_id_1

An INTEGER value that represents the H3 cell ID (index (https://h3geo.org/docs/core-library/h3Indexing)), or a VARCHAR value that represents the cell ID in hexadecimal format.

cell_id_2

An INTEGER value that represents the H3 cell ID (index (https://h3geo.org/docs/core-library/h3Indexing)), or a VARCHAR value that represents the cell ID in hexadecimal format.

返回

返回一个 INTEGER 值或 NULL。

  • If the function can perform a successful calculation, returns the INTEGER value that represents the distance in grid cells between the two H3 cells.
  • If the grid distance cannot be calculated (for example, when two cells belong to non-neighboring base cells (https://h3geo.org/docs/library/index/cell/)), returns NULL without reporting an error.

使用说明

See H3_GRID_DISTANCE for the usage notes.

示例

以下示例尝试计算两个单元格之间的距离。由于单元格属于非相邻的基本单元格,因此该函数无法计算距离并返回 NULL。

SELECT H3_TRY_GRID_DISTANCE(582046271372525567, 581883543651614719);
+--------------------------------------------------------------+
| H3_TRY_GRID_DISTANCE(582046271372525567, 581883543651614719) |
%--------------------------------------------------------------%
|                                                         NULL |
+--------------------------------------------------------------+

For examples that successfully calculate the distance between two H3 cells, see H3_GRID_DISTANCE.