h3
H3 is Uber’s Hexagonal Hierarchical Spatial Index. Full documentation of the project can be found at h3geo. You can also learn more about H3 in the Spatial Indexes section of this documentation.
H3_BOUNDARY
H3_BOUNDARY(index)Description
Returns a geography representing the H3 cell. It will return null on error (invalid input).
index:STRINGThe H3 cell index.
Return type
GEOGRAPHY
Example
SELECT `carto-un`.carto.H3_BOUNDARY('84390cbffffffff');
-- POLYGON((-3.57692743539573 40.6134385959352, -3.85975632308016 ...SELECT `carto-un-eu`.carto.H3_BOUNDARY('84390cbffffffff');
-- POLYGON((-3.57692743539573 40.6134385959352, -3.85975632308016 ...SELECT carto.H3_BOUNDARY('84390cbffffffff');
-- POLYGON((-3.57692743539573 40.6134385959352, -3.85975632308016 ...H3_CENTER
H3_CENTER(index)Description
Returns the center of the H3 cell as a GEOGRAPHY point. It will return null on error (invalid input).
index:STRINGThe H3 cell index.
Return type
GEOGRAPHY
Example
H3_COMPACT
Description
Returns an array with the indexes of a set of hexagons across multiple resolutions that represent the same area as the input set of hexagons.
indexArray:ARRAY<STRING>of H3 cell indices of the same resolution.
Return type
ARRAY<STRING>
Example
H3_DISTANCE
Description
Returns the grid distance between two hexagon indexes. This function may fail to find the distance between two indexes if they are very far apart or on opposite sides of a pentagon. Returns null on failure or invalid input.
origin:STRINGorigin H3 cell index.destination:STRINGdestination H3 cell index.
Return type
INT64
Example
H3_FROMGEOGPOINT
Description
Returns the H3 cell index that the point belongs to in the requested resolution. It will return null on error (invalid geography type or resolution out of bounds). This function is an alias for H3_FROMGEOPOINT.
point:GEOGRAPHYpoint to get the H3 cell from.resolution:INT64number between 0 and 15 with the H3 resolution.
Return type
STRING
Example
H3_FROMLONGLAT
Description
Returns the H3 cell index that the point belongs to in the required resolution. It will return null on error (resolution out of bounds).
longitude:FLOAT64horizontal coordinate of the map.latitude:FLOAT64vertical coordinate of the map.resolution:INT64number between 0 and 15 with the H3 resolution.
Return type
STRING
Example
H3_HEXRING
Description
Returns all cell indexes in a hollow hexagonal ring centered at the origin in no particular order. Unlike H3_KRING, this function will throw an exception if there is a pentagon anywhere in the ring.
origin:STRINGH3 cell index of the origin.size:INT64size of the ring (distance from the origin).
Return type
ARRAY<STRING>
Example
H3_INT_TOSTRING
Description
Converts the integer representation of the H3 index to the string representation.
index:INT64The H3 cell index.
Return type
STRING
Example
H3_ISPENTAGON
Description
Returns true if given H3 index is a pentagon. Returns false otherwise, even on invalid input.
index:STRINGThe H3 cell index.
Return type
BOOLEAN
Example
H3_ISVALID
Description
Returns true when the given index is a valid H3 index, false otherwise.
index:STRINGThe H3 cell index.
Return type
BOOLEAN
Examples
H3_KRING
Description
Returns all cell indexes in a filled hexagonal k-ring centered at the origin in no particular order.
origin:STRINGH3 cell index of the origin.size:INT64size of the ring (distance from the origin).
Return type
ARRAY<STRING>
Example
H3_KRING_DISTANCES
Description
Returns all cell indexes and their distances in a filled hexagonal k-ring centered at the origin in no particular order.
origin:STRINGH3 cell index of the origin.size:INT64size of the ring (distance from the origin).
Return type
ARRAY<STRUCT<index STRING, distance INT64>>
Example
H3_POLYFILL
Description
Returns an array of H3 cell indexes contained in the given geography (Polygon, MultiPolygon) at a requested resolution. Containment is determined by the cells' center. This function is equivalent to H3_POLYFILL_MODE with mode center.
geog:GEOGRAPHYrepresenting the shape to cover.resolution:INT64level of detail. The value must be between 0 and 15 (H3 resolution table).
Use H3_POLYFILL_MODE with mode intersects in the following cases:
You want to provide the minimum covering set of a Polygon, MultiPolygon.
The input geography type is Point, MultiPoint, LineString, MultiLineString.
Return type
ARRAY<STRING>
Examples
H3_POLYFILL_MODE
Description
Returns an array of H3 cell indexes contained in the given geography at a requested resolution. Containment is determined by the mode: center, intersects, contains.
geog:GEOGRAPHYrepresenting the shape to cover.resolution:INT64level of detail. The value must be between 0 and 15 (H3 resolution table).mode:STRINGcenterreturns the indexes of the H3 cells which centers intersect the input geography (polygon). The resulting H3 set does not fully cover the input geography, however, this is significantly faster that the other modes. This mode is not compatible with points or lines. Equivalent toH3_POLYFILL.intersectsreturns the indexes of the H3 cells that intersect the input geography. The resulting H3 set will completely cover the input geography (point, line, polygon).containsreturns the indexes of the H3 cells that are entirely contained inside the input geography (polygon). This mode is not compatible with points or lines.
Mode center:

Mode intersects:

Mode contains:

Return type
ARRAY<STRING>
Examples
H3_POLYFILL_TABLE (BETA)
Description
Returns a table with the H3 cell indexes contained in the given geography at a requested resolution. Containment is determined by the mode: center, intersects, contains. All the attributes except the geography will be included in the output table, clustered by the h3 column.
input_query:STRINGinput data to polyfill. It must contain a columngeomwith the shape to cover. Additionally, other columns can be included.resolution:INT64level of detail. The value must be between 0 and 15 (H3 resolution table).mode:STRINGcenterreturns the indexes of the H3 cells which centers intersect the input geography (polygon). The resulting H3 set does not fully cover the input geography, however, this is significantly faster that the other modes. This mode is not compatible with points or lines. Equivalent toH3_POLYFILL.intersectsreturns the indexes of the H3 cells that intersect the input geography. The resulting H3 set will completely cover the input geography (point, line, polygon).containsreturns the indexes of the H3 cells that are entirely contained inside the input geography (polygon). This mode is not compatible with points or lines.
output_table:STRINGname of the output table to store the results of the polyfill.
Mode center:

Mode intersects:

Mode contains:

Output
The results are stored in the table named <output_table>, which contains the following columns:
h3:STRINGthe geometry of the considered point.The rest of columns included in
input_queryexceptgeom.
Examples
H3_RESOLUTION
Description
Returns the H3 cell resolution as an integer. It will return null on error (invalid input).
index:STRINGThe H3 cell index.
Return type
INT64
Example
H3_STRING_TOINT
Description
Converts the string representation of the H3 index to the integer representation.
index:STRINGThe H3 cell index.
Return type
INT64
Example
H3_TOCHILDREN
Description
Returns an array with the H3 indexes of the children/descendents of the given hexagon at the given resolution.
index:STRINGThe H3 cell index.resolution:INT64number between 0 and 15 with the H3 resolution.
Return type
ARRAY<STRING>
Example
H3_TOPARENT
Description
Returns the H3 cell index of the parent of the given hexagon at the given resolution.
index:STRINGThe H3 cell index.resolution:INT64number between 0 and 15 with the H3 resolution.
Return type
STRING
Example
H3_UNCOMPACT
Description
Returns an array with the H3 indexes of a set of hexagons of the same resolution that represent the same area as the compacted input hexagons.
indexArray:ARRAY<STRING>of H3 cell indices.resolution:INT64number between 0 and 15 with the H3 resolution.
Return type
ARRAY<STRING>
Example
This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 960401.
Last updated
Was this helpful?
