H3_CELL_TO_BOUNDARY

Return the boundary of an H3 cell as a WKT POLYGON string.

Category: h3Returns: STRINGDialect: Standard

Syntax

H3_CELL_TO_BOUNDARY(cell)

Description

## Overview Returns the boundary of an H3 cell as a WKT POLYGON string of the form `POLYGON((lng1 lat1, lng2 lat2, ...))`. The output follows WKT convention with (longitude, latitude) coordinate order and repeats the first vertex at the end to close the ring. Use this function to render H3 cells on a map, export to a GIS tool, feed into a downstream geometry parser, or overlay cell boundaries for debugging. Most H3 cells are hexagons with six vertices; the twelve pentagon cells at each resolution produce a polygon with only five vertices. Both cases are returned in the same WKT POLYGON format. ## Behavior - Returns a STRING in WKT POLYGON format with (lng lat) coordinate order. - Returns NULL if the input is NULL or not a valid H3 cell index. - Hexagon cells yield 6 distinct vertices plus a closing repeat (7 coordinate pairs total). - Pentagon cells yield 5 distinct vertices plus a closing repeat (6 coordinate pairs total). - Vertices are ordered consistently around the cell; the winding direction is stable. - Coordinates are emitted with 10 decimal places of precision, which is sub-centimeter accurate. - Deterministic: the same cell always returns the same WKT string. ## H3 resolution reference | Res | Average edge length | Average hex area | | --- | --- | --- | | 0 | 1,107 km | 4.25 million km^2 | | 7 | 1.22 km | 5.16 km^2 | | 9 | 174 m | 0.11 km^2 | | 12 | 9.4 m | 307 m^2 | | 15 | 0.5 m | 0.9 m^2 | ## Compatibility - The returned string is valid WKT and parses cleanly with ST_GEOMFROMTEXT, any OGC-compliant GIS tool, or a GeoJSON converter.

Parameters

NameTypeDescription
cellSpecifies the H3 cell index whose boundary polygon to construct. Must be a valid H3 cell. NULL or invalid cells return NULL.

Examples

-- Returns POLYGON((lng1 lat1, lng2 lat2, ...)) for a resolution 7 cell over London.
SELECT H3_CELL_TO_BOUNDARY(H3_LATLNG_TO_CELL(51.5074, -0.1278, 7)) AS boundary_wkt;
-- Produce one row per H3 cell with its WKT polygon, ready to feed into a GIS tool.
SELECT
  h3_cell,
  H3_CELL_TO_BOUNDARY(h3_cell) AS boundary_wkt,
  H3_CELL_AREA(h3_cell)         AS area_m2
FROM mobility.curated.h3_hourly
WHERE event_date = CURRENT_DATE - INTERVAL 1 DAY;
-- Pentagon cells have only 5 vertices; the WKT still closes by repeating the first vertex.
WITH pentagon_cell AS (
  SELECT cell_id
  FROM spatial.reference.h3_pentagons
  WHERE resolution = 5
  LIMIT 1
)
SELECT cell_id, H3_CELL_TO_BOUNDARY(cell_id) AS boundary_wkt
FROM pentagon_cell;
-- Pair the cell center with its boundary for map overlays.
SELECT
  H3_CELL_TO_LAT(c)      AS center_lat,
  H3_CELL_TO_LNG(c)      AS center_lng,
  H3_CELL_TO_BOUNDARY(c) AS boundary_wkt
FROM (SELECT H3_LATLNG_TO_CELL(35.6762, 139.6503, 8) AS c);
-- Invalid cell returns NULL instead of raising an error.
SELECT H3_CELL_TO_BOUNDARY(CAST(0 AS BIGINT)) AS boundary_wkt;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →