Skip to main content

Traversal

Functions for finding neighboring cells and collecting cells within a range. See the Traversal example.

Each A5 cell has exactly 5 edge neighbors, which can be obtained using the gridDisk function. If the vertex neighbors are required, gridDiskVertex can be used. For broader range queries sphericalCap provides all the cells within a great-circle radius. To trace cells along a path, use lineStringToCells.

In order to save memory, the returned cells from gridDisk, gridDiskVertex and sphericalCap are compacted into a covering: the cells, then a compaction marker recording their resolution. Coverings can be combined with the set operations.

gridDisk​

Returns all cells within k edge-sharing hops of a center cell.

At each step, only edge-sharing neighbors (5 per cell) are followed.

The result is compacted — use uncompact to expand it to the resolution of the center cell.

a5_grid_disk(cell UBIGINT, k INTEGER) -> UBIGINT[]

Parameters​

  • cellId (bigint) Center A5 cell identifier
  • k (number) Number of hops (0 returns just the center cell)

Return value​

  • (BigUint64Array) Compacted cells in the disk sorted in curve order, then the compaction marker

Example​

-- center + 5 edge neighbors (compacted)
SELECT a5_grid_disk(a5_lonlat_to_cell(2.3522, 48.8566, 10), 1) AS ring1;
-- center + ring 1 + ring 2 (uncompacted)
SELECT a5_uncompact(a5_grid_disk(a5_lonlat_to_cell(2.3522, 48.8566, 10), 2)) AS ring2;

gridDiskVertex​

Returns all cells within k hops of a center cell, following both edge-sharing and vertex-sharing neighbors.

The result is compacted — use uncompact to expand it to the resolution of the center cell.

a5_grid_disk_vertex(cell UBIGINT, k INTEGER) -> UBIGINT[]

Parameters​

  • cellId (bigint) Center A5 cell identifier
  • k (number) Number of hops (0 returns just the center cell)

Return value​

  • (BigUint64Array) Compacted cells in the disk sorted in curve order, then the compaction marker

sphericalCap​

Computes all cells whose centers fall within a great-circle radius from the center of a given cell.

The result is compacted — use uncompact to expand it to the resolution of the center cell.

a5_spherical_cap(cell UBIGINT, radius DOUBLE) -> UBIGINT[]

Parameters​

  • cellId (bigint) Center A5 cell identifier
  • radius (number) Radius in meters

Return value​

Example​

-- 500 km
SELECT a5_spherical_cap(a5_lonlat_to_cell(2.3522, 48.8566, 10), 500000) AS compact;
-- All cells at resolution 10
SELECT unnest(a5_uncompact(a5_spherical_cap(a5_lonlat_to_cell(2.3522, 48.8566, 10), 500000))) AS cell;