is Uber’s Hexagonal Hierarchical Spatial Index. Full documentation of the project can be found at . You can also learn more about H3 in the of this documentation.
H3_BOUNDARY
H3_BOUNDARY(index)
Description
Returns a geography representing the H3 cell. It will return null on error (invalid input).
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.
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.
SELECT h3
FROM UNNEST(`carto-un`.carto.H3_POLYFILL(
ST_GEOGFROMTEXT('POLYGON ((-3.71219873428345 40.413365349070865, -3.7144088745117 40.40965661286395, -3.70659828186035 40.409525904775634, -3.71219873428345 40.413365349070865))'),
9
)) AS h3;
-- 89390cb1b4bffff
SELECT h3
FROM UNNEST(`carto-un-eu`.carto.H3_POLYFILL(
ST_GEOGFROMTEXT('POLYGON ((-3.71219873428345 40.413365349070865, -3.7144088745117 40.40965661286395, -3.70659828186035 40.409525904775634, -3.71219873428345 40.413365349070865))'),
9
)) AS h3;
-- 89390cb1b4bffff
SELECT h3
FROM UNNEST(carto.H3_POLYFILL(
ST_GEOGFROMTEXT('POLYGON ((-3.71219873428345 40.413365349070865, -3.7144088745117 40.40965661286395, -3.70659828186035 40.409525904775634, -3.71219873428345 40.413365349070865))'),
9
)) AS h3;
-- 89390cb1b4bffff
SELECT h3
FROM <project>.<dataset>.<table>,
UNNEST(`carto-un`.carto.H3_POLYFILL(geog, 9)) AS h3;
SELECT h3
FROM <project>.<dataset>.<table>,
UNNEST(`carto-un-eu`.carto.H3_POLYFILL(geog, 9)) AS h3;
SELECT h3
FROM <project>.<dataset>.<table>,
UNNEST(carto.H3_POLYFILL(geog, 9)) AS h3;
Additional examples
H3_POLYFILL_MODE
H3_POLYFILL_MODE(geog, resolution, 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: GEOGRAPHY representing the shape to cover.
mode: STRING
intersects returns the indexes of the H3 cells that intersect the input geography. The resulting H3 set will completely cover the input geography (point, line, polygon).
contains returns the indexes of the H3 cells that are entirely contained inside the input geography (polygon). This mode is not compatible with points or lines.
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: STRING input data to polyfill. It must contain a column geom with the shape to cover. Additionally, other columns can be included.
mode: STRING
intersects returns the indexes of the H3 cells that intersect the input geography. The resulting H3 set will completely cover the input geography (point, line, polygon).
contains returns 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: STRING name 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: STRING the geometry of the considered point.
The rest of columns included in input_query except geom.
Examples
CALL `carto-un`.carto.H3_POLYFILL_TABLE(
"SELECT ST_GEOGFROMTEXT('POLYGON ((-3.71219873428345 40.413365349070865, -3.7144088745117 40.40965661286395, -3.70659828186035 40.409525904775634, -3.71219873428345 40.413365349070865))') AS geom",
9, 'intersects',
'<project>.<dataset>.<output_table>'
);
-- The table `<project>.<dataset>.<output_table>` will be created
-- with column: h3
CALL `carto-un-eu`.carto.H3_POLYFILL_TABLE(
"SELECT ST_GEOGFROMTEXT('POLYGON ((-3.71219873428345 40.413365349070865, -3.7144088745117 40.40965661286395, -3.70659828186035 40.409525904775634, -3.71219873428345 40.413365349070865))') AS geom",
9, 'intersects',
'<project>.<dataset>.<output_table>'
);
-- The table `<project>.<dataset>.<output_table>` will be created
-- with column: h3
CALL carto.H3_POLYFILL_TABLE(
"SELECT ST_GEOGFROMTEXT('POLYGON ((-3.71219873428345 40.413365349070865, -3.7144088745117 40.40965661286395, -3.70659828186035 40.409525904775634, -3.71219873428345 40.413365349070865))') AS geom",
9, 'intersects',
'<project>.<dataset>.<output_table>'
);
-- The table `<project>.<dataset>.<output_table>` will be created
-- with column: h3
CALL `carto-un`.carto.H3_POLYFILL_TABLE(
'SELECT geom, name, value FROM `<project>.<dataset>.<table>`',
9, 'center',
'<project>.<dataset>.<output_table>'
);
-- The table `<project>.<dataset>.<output_table>` will be created
-- with columns: h3, name, value
CALL `carto-un-eu`.carto.H3_POLYFILL_TABLE(
'SELECT geom, name, value FROM `<project>.<dataset>.<table>`',
9, 'center',
'<project>.<dataset>.<output_table>'
);
-- The table `<project>.<dataset>.<output_table>` will be created
-- with columns: h3, name, value
CALL carto.H3_POLYFILL_TABLE(
'SELECT geom, name, value FROM `<project>.<dataset>.<table>`',
9, 'center',
'<project>.<dataset>.<output_table>'
);
-- The table `<project>.<dataset>.<output_table>` will be created
-- with columns: h3, name, value
H3_RESOLUTION
H3_RESOLUTION(index)
Description
Returns the H3 cell resolution as an integer. It will return null on error (invalid input).
If you want the distance in meters use between the cells () or their centroid.
resolution: INT64 number between 0 and 15 with the .
If you want the cells covered by a POLYGON see .
resolution: INT64 number between 0 and 15 with the .
Returns all cell indexes in a hollow hexagonal ring centered at the origin in no particular order. Unlike , this function will throw an exception if there is a pentagon anywhere in the ring.
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 with mode center.
resolution: INT64 level of detail. The value must be between 0 and 15 ().
Use with mode intersects in the following cases:
resolution: INT64 level of detail. The value must be between 0 and 15 ().
center returns 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 to .
resolution: INT64 level of detail. The value must be between 0 and 15 ().
center returns 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 to .
resolution: INT64 number between 0 and 15 with the .
resolution: INT64 number between 0 and 15 with the .
Returns an array with the H3 indexes of a set of hexagons of the same resolution that represent the same area as the input hexagons.
resolution: INT64 number between 0 and 15 with the .
This project has received funding from the research and innovation programme under grant agreement No 960401.