h3_try_polyfillash3string function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 11.2 and above

Behaves the same as h3_polyfillash3string, except that NULL is returned instead of an error if the first argument is invalid. More precisely, returns an ARRAY of H3 cell IDs (represented as STRING) corresponding to hexagons or pentagons, of the specified resolution, that are contained by the input areal geography.

Syntax

h3_try_polyfillash3string ( geographyExpr, resolutionExpr )

Arguments

  • geographyExpr: A BINARY or STRING expression representing an areal geography (polygon or multipolygon) in WKB, WKT, or GeoJSON. The geography is expected to have longitude and latitude coordinates in degrees that refer to the WGS84 coordinate reference system.

  • resolutionExpr: An INT expression, whose value is expected to be between 0 and 15 inclusive, specifying the resolution for the H3 cells.

Returns

An ARRAY of STRING values corresponding to the H3 cell IDs, of the specified resolution, that are contained by the input areal geography.

The function returns NULL if any of the input expressions is NULL. If the first input argument is of type BINARY, the input value is expected to be the WKB description of a polygon or a multipolygon. If the first input argument is of type STRING, the input value is expected to be either the WKT or the GeoJSON description of a polygon or a multipolygon. The dimension of the input polygon or multipolygon can be 2D, 3DZ, 3DM, or 4D. The function returns NULL if the first argument corresponds to an invalid WKB, WKT, or GeoJSON or does not represent a polygon or a multipolygon.

Error conditions

Examples

-- Simple example where the input is a triangle in WKT format.
> SELECT h3_try_polyfillash3string('POLYGON((-122.4194 37.7749,-118.2437 34.0522,-74.0060 40.7128,-122.4194 37.7749))', 2)
  [82268ffffffffff,82269ffffffffff,822987fffffffff,8226e7fffffffff,822997fffffffff,8226f7fffffffff,822657fffffffff,8229affffffffff]

-- Simple example where the input is a triangle in hexadecimal WKB format.
> SELECT h3_try_polyfillash3string(unhex('0103000000010000000400000050fc1873d79a5ec0d0d556ec2fe342404182e2c7988f5dc0f46c567dae064140aaf1d24d628052c05e4bc8073d5b444050fc1873d79a5ec0d0d556ec2fe34240'), 2)
  [82268ffffffffff,82269ffffffffff,822987fffffffff,8226e7fffffffff,822997fffffffff,8226f7fffffffff,822657fffffffff,8229affffffffff]

-- The input is invalid.
> SELECT h3_try_polyfillash3string('Not-a-valid-rep', 2)
  null

-- Resolution is out of range.
> SELECT h3_try_polyfillash3string('POLYGON((-122.4194 37.7749,-118.2437 34.0522,-74.0060 40.7128,-122.4194 37.7749))', 16)
  [H3_INVALID_RESOLUTION_VALUE] H3 resolution 16 must be between 0 and 15, inclusive