Skip to content

H3_GRID_DISTANCE ​

Returns the distance between two H3 cells specified by their IDs, measured in grid cells. Note that this is the shortest path along the H3 grid, not necessarily the shortest path over the surface of the Earth (a geodesic).

Syntax ​

sql
H3_GRID_DISTANCE(<cell1>, <cell2>)

Arguments ​

  • <cell1>: A BIGINT H3 cell ID.
  • <cell2>: A BIGINT H3 cell ID.

Returns ​

Returns a BIGINT value representing the distance in grid cells between two H3 cells. An error is returned if the two input cells are not the same resolution.

Example ​

sql
SELECT h3_grid_distance(h3_point_to_cell('POINT(0 0)', 3), h3_point_to_cell('POINT(10 0)', 3));
-- 10