Jaa


h3_boundaryasgeojson function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 11.3 LTS and above

Returns the polygonal boundary of the input H3 cell in GeoJSON format.

Syntax

h3_boundaryasgeojson ( h3CellIdExpr )

Arguments

  • h3CellIdExpr: A BIGINT expression, or a hexadecimal STRING expression representing an H3 cell ID.

Returns

A value of the type STRING representing the polygonal boundary of the input H3 cell in GeoJSON format.

The function returns NULL if the input expression is NULL. The function does partial validation regarding whether the input argument is a valid H3 cell ID. A necessary, but not sufficient condition for a valid H3 ID is that its value is between 0x08001fffffffffff and 0x08ff3b6db6db6db6. The behavior of the function is undefined if the input cell ID is not a valid cell ID.

Error conditions

  • If h3CellIdExpr is a STRING that cannot be converted to a BIGINT or corresponds to a BIGINT value that is either smaller than 0x08001fffffffffff or larger than 0x08ff3b6db6db6db6, the function returns H3_INVALID_CELL_ID.

Examples

-- Input a BIGINT representing a hexagonal cell.
> SELECT h3_boundaryasgeojson(599686042433355775)
  {"type":"Polygon","coordinates":[[[-121.91508032706,37.271355866732],[-121.86222328902,37.353926450852],[-121.9235499963,37.428341186094],[-122.03773496427 37.420128677678],[-122.09042892904,37.337556084353],[-122.02910130919,37.263197974618],[-121.91508032706,37.271355866732]]]}

-- Input a STRING representing a pentagonal cell.
> SELECT h3_boundaryasgeojson('8009fffffffffff')
  {"type":"Polygon","coordinates":[[[-10.444977544778,63.095054077525],[5.5236465492903,55.706768465152],[25.082722326708,58.401544870353],[31.831280499087,68.92995788194],[0.32561035194326,73.310223685444],[-10.444977544778,63.095054077525]]]}

-- Input is an invalid H3 cell ID.
> SELECT h3_boundaryasgeojson(0)
  [H3_INVALID_CELL_ID] 0 is not a valid H3 cell ID