ClickHouse function reference

h3IsValid

Verifies whether the number is a valid H3 index.

Syntax

h3IsValid(h3index)

Arguments

  • h3index (UInt64): Hexagon index number.

Returns

  • 1 — The number is a valid H3 index. [UInt8]
  • 0 — The number is not a valid H3 index. [UInt8]

Example

SELECT h3IsValid(630814730351855103) AS is_valid_h3;

Result:

| is_valid_h3 |
|-------------|
| 1           |

This example checks if the given number is a valid H3 index. The result 1 indicates that it is indeed a valid H3 index.

The H3 index system is used for geospatial indexing, where the Earth’s surface is divided into hexagonal cells. This function is useful for validating H3 indexes before using them in other H3-related operations.

h3GetResolution

Returns the resolution of the given H3 index.

Syntax:

h3GetResolution(h3index)

Arguments:

  • h3index (UInt64): Hexagon index number.

Returns:

  • Index resolution. Range: [0, 15]. Type: UInt8.
  • If the index is not valid, the function returns a random value. Use h3IsValid to verify the index.

Example:

SELECT h3GetResolution(639821929606596015) AS resolution;

Result:

| resolution |
|------------|
| 14         |

In this example, we determine the resolution of a H3 index. The result shows that this particular area is represented at resolution 14, which provides a very fine-grained hexagonal grid for precise location analysis.

Here’s the updated markdown with the requested changes:

h3EdgeAngle

Calculates the average length of the H3 hexagon edge in degrees for a given resolution.

Syntax:

h3EdgeAngle(resolution)

Arguments:

  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • The average length of the H3 hexagon edge in degrees. (Float64)

Example:

SELECT h3EdgeAngle(10) AS edge_angle;

Result:

| edge_angle              |
|-------------------------|
| 0.0005927224846720883   |

This example calculates the average edge length in degrees for H3 hexagons at resolution 10. The result shows that each edge is approximately 0.0006 degrees long.

The edge angle becomes smaller as the resolution increases, reflecting the finer granularity of the H3 grid at higher resolutions.

h3EdgeLengthM

Calculates the average length of the H3 hexagon edge in meters for a given resolution.

Syntax:

h3EdgeLengthM(resolution)

Arguments:

  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • The average length of the H3 hexagon edge in meters. (Float64)

Example:

SELECT h3EdgeLengthM(10) AS edge_length_m;

Result:

| edge_length_m |
|---------------|
| 65.90780749   |

In this example, we calculate the average edge length in meters for H3 hexagons at resolution 10. This information can be useful for various geospatial applications, such as determining the size of taco delivery zones or planning optimal routes for food trucks.

The edge length decreases as the resolution increases, providing finer granularity for higher resolution indexes.

h3EdgeLengthKm

Calculates the average length of the H3 hexagon edge in kilometers for a given resolution.

Syntax:

h3EdgeLengthKm(resolution)

Arguments:

  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • The average length of the H3 hexagon edge in kilometers. (Float64)

Example:

SELECT h3EdgeLengthKm(5) AS edge_length_km;

Result:

| edge_length_km |
|----------------|
| 8.544408276    |

This example calculates the average edge length in kilometers for H3 hexagons at resolution 5. The result shows that at this resolution, each hexagon edge is approximately 8.54 km long.

The edge length decreases as the resolution increases, providing finer granularity for location representation.

geoToH3

Returns the H3 index of the point (lon, lat) at the specified resolution.

Syntax:

geoToH3(lon, lat, resolution)

Arguments:

  • lon (Float64): Longitude.
  • lat (Float64): Latitude.
  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • Hexagon index number. (UInt64)
  • 0 in case of error.

Example:

SELECT geoToH3(37.79506683, 55.71290588, 15) AS h3Index;

Result:

| h3Index            |
|--------------------|
| 644325524701193974 |

This example calculates the H3 index for a taco truck location in Mexico City at resolution 15. The resulting index can be used for efficient geospatial operations and analysis of taco truck distribution patterns.

The H3 index is particularly useful for analyzing taco truck density, optimizing delivery routes, or identifying underserved areas in the taco market.

h3ToGeo

Converts an H3 index to geographic coordinates (longitude and latitude).

Syntax:

h3ToGeo(h3index)

Arguments:

  • h3index (UInt64): H3 index.

Returns:

  • A tuple containing two values: (lon, lat).
    • lon (Float64): Longitude of the H3 cell center.
    • lat (Float64): Latitude of the H3 cell center.

Example:

SELECT h3ToGeo(644325524701193974) AS coordinates;

Result:

| coordinates                             |
|-----------------------------------------|
| (37.79506616830252,55.71290243145668)   |

In this example, we convert an H3 index representing a location of a taco truck to its geographic coordinates. The result shows the longitude and latitude of the center of the H3 cell where the taco truck is located.

h3ToGeoBoundary

Returns an array of coordinates representing the boundary of the H3 cell.

Syntax:

h3ToGeoBoundary(h3index)

Arguments:

  • h3index (UInt64): H3 cell index.

Returns:

  • Array of pairs (lon, lat) representing the boundary coordinates. Array(Tuple(Float64, Float64))

Example:

SELECT h3ToGeoBoundary(599686042433355775) AS taco_zone_boundary;

Result:

| taco_zone_boundary                                                                                                                                                   |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [(37.2713558667319,-121.91508032705622),(37.353926450852256,-121.8622232890249),(37.42834118609435,-121.92354999630156),(37.42012867767779,-122.03773496427027),     |
|  (37.33755608435299,-122.090428929044),(37.26319797461824,-122.02910130919001)]                                                                                      |

This function is useful for visualizing H3 cells or performing geometric operations on their boundaries. In this example, it returns the coordinates of the vertices that form the boundary of a hexagonal “taco zone” represented by the given H3 index.

h3kRing

Lists all the H3 hexagons in a ring of radius k around the given hexagon in random order.

Syntax:

h3kRing(h3index, k)

Arguments:

  • h3index (UInt64): Hexagon index number representing the center.
  • k (Integer): Radius of the ring.

Returns:

Array of H3 indexes representing the hexagons in the ring. [Array(UInt64)]

Example:

SELECT h3kRing(644325529233966508, 1) AS taco_delivery_zone;

Result:

| taco_delivery_zone                                                                   |
|--------------------------------------------------------------------------------------|
| [644325529233966508,644325529233966497,644325529233966510,644325529233966504,        |
|  644325529233966509,644325529233966355,644325529233966354]                           |

In this example, taco_delivery_zone represents the hexagons surrounding the central taco shop location, which could be used to define a delivery area or analyze nearby competitors.

The order of hexagons in the resulting array is not guaranteed and may change between calls.

This function is useful for creating circular zones around a point of interest, such as determining delivery areas for a taco shop or analyzing the distribution of taco trucks in a city.

h3GetBaseCell

Returns the base cell number of the given H3 index.

Syntax:

h3GetBaseCell(index)

Arguments:

  • index (UInt64): Hexagon index number.

Returns:

  • Hexagon base cell number. [UInt8]

Example:

SELECT h3GetBaseCell(612916788725809151) AS base_cell;

Result:

| base_cell |
|-----------|
| 12        |

In this example, we determine the base cell of a taco truck’s location using its H3 index. The result shows that the taco truck is located in base cell 12, which could represent a specific region or district in the taco delivery service area.

h3HexAreaM2

Returns the average hexagon area in square meters at the given H3 resolution.

Syntax:

h3HexAreaM2(resolution)

Arguments:

  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • Area in square meters. (Float64)

Example:

SELECT h3HexAreaM2(7) AS taco_stand_area;

Result:

| taco_stand_area |
|-----------------|
| 5161294.593708  |

In this example, we calculate the average area of a hexagon at resolution 7, which could represent the coverage area of a taco stand. The result shows that each hexagon at this resolution covers approximately 5.16 square kilometers.

The area of hexagons can vary slightly depending on their location on the Earth’s surface due to the projection used in the H3 system.

h3HexAreaKm2

Returns the average hexagon area in square kilometers at the given H3 resolution.

Syntax:

h3HexAreaKm2(resolution)

Arguments:

  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • Area in square kilometers. (Float64)

Example:

SELECT h3HexAreaKm2(7) AS taco_delivery_zone_area;

Result:

| taco_delivery_zone_area |
|-------------------------|
| 5.161293851260108       |

In this example, we calculate the average area of a hexagon at resolution 7, which could represent a taco delivery zone. The result shows that each hexagon covers approximately 5.16 square kilometers.

The area of hexagons varies slightly depending on their position on the Earth’s surface. This function returns the average area for the given resolution.

h3IndexesAreNeighbors

Determines if two H3 indexes are neighbors.

Syntax:

h3IndexesAreNeighbors(h3index1, h3index2)

Arguments:

  • h3index1 (UInt64): First H3 index.
  • h3index2 (UInt64): Second H3 index.

Returns:

  • 1 if the indexes are neighbors, 0 otherwise. [UInt8]

Example:

SELECT
	h3IndexesAreNeighbors(
		geoToH3(37.7752, -122.4185, 9),  -- Taco Store
		geoToH3(37.7752, -122.4187, 9)   -- Neighboring taco truck
	) AS are_neighbors;

Result:

| are_neighbors |
|---------------|
| 1             |

In this example, we check if a Taco Store location and a neighboring taco truck (represented by their H3 indexes) are neighbors. The result 1 indicates that they are indeed neighbors in the H3 grid system.

This function is useful for spatial analysis, such as finding adjacent areas or checking proximity in location-based applications.

h3ToChildren

Returns an array of child indexes for the given H3 index at the specified resolution.

Syntax:

h3ToChildren(index, resolution)

Arguments:

  • index (UInt64): The parent H3 index.
  • resolution (UInt8): The desired resolution for the child indexes. Range: [0, 15].

Returns:

  • An array of child H3 indexes. [Array(UInt64)]

Example:

SELECT
	h3ToChildren(599405990164561919, 6) AS taco_delivery_zones;

Result:

| taco_delivery_zones                                                                                                                       |
|-------------------------------------------------------------------------------------------------------------------------------------------|
| [603909588852408319,603909588986626047,603909589120843775,603909589255061503,603909589389279231,603909589523496959,603909589657714687]    |

In this example, we’re dividing a larger taco delivery area (represented by the parent H3 index) into smaller, more precise delivery zones at resolution 6.

The number of child indexes returned depends on the difference between the resolution of the input index and the requested resolution. A larger difference will result in more child indexes.

h3ToParent

Returns the parent (coarser) index containing the given H3 index.

Syntax:

h3ToParent(index, resolution)

Arguments:

  • index (UInt64): Hexagon index number.
  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • Parent H3 index. UInt64.

Example:

SELECT h3ToParent(599405990164561919, 3) AS parent_index;

Result:

| parent_index       |
|--------------------|
| 590398848891879423 |

In this example, we find the parent index at resolution 3 for the given H3 index. This can be useful for aggregating data from finer resolutions to coarser ones in geospatial analysis, such as grouping taco shop locations into larger areas.

h3ToString

Converts the H3Index representation of an H3 index to its string representation.

Syntax:

h3ToString(index)

Arguments:

  • index (UInt64): H3 index number.

Returns:

  • String representation of the H3 index. [String]

Example:

SELECT h3ToString(617420388352917503) AS h3_string;

Result:

| h3_string       |
|-----------------|
| 89184926cdbffff |

In this example, we convert the numeric H3 index of a taco shop location to its string representation, which can be useful for human-readable output or when interfacing with systems that expect H3 indexes in string format.

stringToH3

Converts the string representation of an H3 index to its 64-bit integer representation.

Syntax:

stringToH3(index_str)

Arguments:

  • index_str (String): String representation of the H3 index.

Returns:

  • The 64-bit integer representation of the H3 index. [UInt64]
  • Returns 0 if the input is not a valid H3 index string.

Example:

SELECT stringToH3('89184926cc3ffff') AS taco_zone;

Result:

| taco_zone           |
|---------------------|
| 617420388351344639  |

In this example, we convert a string representation of an H3 index (possibly representing a taco delivery zone) to its 64-bit integer form.

This function is the inverse of h3ToString. It’s useful when you have H3 indexes stored as strings and need to perform operations that require the numeric representation.

h3GetResolution

Returns the resolution of the given H3 index.

Syntax:

h3GetResolution(h3index)

Arguments:

  • h3index (UInt64): Hexagon index number.

Returns:

  • Index resolution. Range: [0, 15]. Type: UInt8.
  • If the index is not valid, the function returns a random value. Use h3IsValid to verify the index.

Example:

SELECT h3GetResolution(639821929606596015) AS resolution;

Result:

| resolution |
|------------|
| 14         |

In this example, we determine the resolution of a H3 index. The result shows that this particular area is represented at resolution 14, which provides a very fine-grained hexagonal grid for precise location analysis.

h3IsResClassIII

Returns whether the H3 index has a resolution with Class III orientation.

Syntax:

h3IsResClassIII(index)

Arguments:

  • index (UInt64): Hexagon index number.

Returns:

  • 1 (UInt8): Index has a resolution with Class III orientation.
  • 0 (UInt8): Index doesn’t have a resolution with Class III orientation.

Example:

SELECT h3IsResClassIII(599686042433355775) AS is_class_iii;

Result:

| is_class_iii |
|--------------|
| 1            |

In this example, we check if the H3 index representing a taco shop location has a Class III orientation. A result of 1 indicates that it does, which might affect how neighboring hexagons are arranged around this location.

h3IsPentagon

Returns whether the given H3 index represents a pentagonal cell.

Syntax:

h3IsPentagon(index)

Parameter:

  • index (UInt64): Hexagon index number.

Returns:

  • 1 — Index represents a pentagonal cell. UInt8.
  • 0 — Index doesn’t represent a pentagonal cell. UInt8.

Example:

SELECT h3IsPentagon(599686042433355775) AS is_pentagon;

Result:

| is_pentagon |
|-------------|
| 0           |

In this example, we check if the H3 index 599686042433355775 represents a pentagonal cell. The result 0 indicates that it does not.

Pentagonal cells are special cases in the H3 grid system, occurring 12 times per resolution (except for resolution 0, which has 5 pentagons). They are important to handle correctly in certain geometric operations.

h3GetFaces

Returns the icosahedron faces intersected by a given H3 index.

Syntax:

h3GetFaces(index)

Arguments:

  • index (UInt64): H3 index number.

Returns:

Array containing icosahedron faces intersected by the given H3 index. [Array(UInt64)]

Example:

SELECT h3GetFaces(599686042433355775) AS taco_faces;

Result:

| taco_faces |
|------------|
| [7]        |

In this example, we determine which icosahedron face(s) are intersected by the H3 index representing a taco truck’s location. The result [7] indicates that this H3 index intersects with face 7 of the icosahedron.

The icosahedron is the base geometric shape used in the H3 system. Understanding which faces are intersected can be useful for certain geographic analyses or optimizations.

h3CellAreaM2

Returns the exact area of a specific H3 cell in square meters.

Syntax:

h3CellAreaM2(index)

Arguments:

  • index (UInt64): H3 index number.

Returns:

  • The exact area of the H3 cell in square meters. [Float64]

Example:

SELECT h3CellAreaM2(599686042433355775) AS taco_stand_area;

Result:

| taco_stand_area     |
|---------------------|
| 265092558.12828755  |

In this example, we calculate the area of a hypothetical taco stand location represented by the H3 index. The result shows the exact area of the H3 cell in square meters, which could be useful for analyzing the coverage or distribution of taco stands across different H3 cells.

h3CellAreaRads2

Returns the exact area of a specific H3 cell in square radians.

Syntax:

h3CellAreaRads2(index)

Arguments:

  • index (UInt64): H3 index of the cell.

Returns:

  • The exact area of the cell in square radians. (Float64)

Example:

SELECT h3CellAreaRads2(599686042433355775) AS cell_area_rads2;

Result:

| cell_area_rads2        |
|------------------------|
| 0.00000653102501064186 |

This example calculates the area in square radians for a specific H3 cell, which could represent a taco delivery zone. The result is a precise measurement that can be used for various geospatial calculations, such as determining the coverage area of a taco truck’s service region.

h3ToCenterChild

Returns the center child (finer) H3 index contained by the given H3 index at the specified resolution.

Syntax:

h3ToCenterChild(index, resolution)

Arguments:

  • index (UInt64): H3 index of the parent hexagon.
  • resolution (UInt8): Desired resolution for the child index. Range: [0, 15].

Returns:

  • H3 index of the center child hexagon. (UInt64)

Example:

SELECT
	h3ToCenterChild(599405990164561919, 7) AS centerChild;

Result:

| centerChild         |
|---------------------|
| 608413188362338303  |

In this example, we find the center child of a hexagon at resolution 6 (represented by the index 599405990164561919) at the next finer resolution (7). The result is the H3 index of the central hexagon among the seven smaller hexagons that make up the original hexagon.

This function is useful for hierarchical spatial analysis, allowing you to zoom in on the central part of a hexagonal area while maintaining the H3 grid structure.

h3ExactEdgeLengthM

Returns the exact edge length of the unidirectional edge represented by the input H3 index in meters.

Syntax:

h3ExactEdgeLengthM(index)

Arguments:

  • index (UInt64): Hexagon index number.

Returns:

  • Exact edge length in meters. (Float64)

Example:

SELECT h3ExactEdgeLengthM(1310277011704381439) AS exactEdgeLengthM;

Result:

| exactEdgeLengthM     |
|----------------------|
| 195449.63163407316   |

This function is useful for precise distance calculations in geospatial applications, such as measuring the exact length of taco truck routes between H3 cells.

h3ExactEdgeLengthKm

Returns the exact edge length of the unidirectional edge represented by the input H3 index in kilometers.

Syntax:

h3ExactEdgeLengthKm(index)

Arguments:

  • index (UInt64): Hexagon index number.

Returns:

  • Exact edge length in kilometers. (Float64)

Example:

SELECT h3ExactEdgeLengthKm(1310277011704381439) AS exactEdgeLengthKm;

Result:

| exactEdgeLengthKm   |
|---------------------|
| 195.44963163407317  |

This function is useful for precise distance calculations in geospatial applications, such as determining the exact length of taco delivery routes optimized using H3 indexes.

h3ExactEdgeLengthRads

Returns the exact edge length of the unidirectional edge represented by the input H3 index in radians.

Syntax:

h3ExactEdgeLengthRads(index)

Arguments:

  • index (UInt64): Hexagon index number.

Returns:

  • Exact edge length in radians. (Float64)

Example:

SELECT h3ExactEdgeLengthRads(1310277011704381439) AS exactEdgeLengthRads;

Result:

| exactEdgeLengthRads   |
|-----------------------|
| 0.030677980118976447  |

In this example, we calculate the exact edge length in radians for the H3 index representing a taco shop location. This can be useful for precise distance calculations in geospatial taco delivery optimization algorithms.

h3NumHexagons

Returns the number of unique H3 indices at the given resolution.

Syntax:

h3NumHexagons(resolution)

Arguments:

  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

  • Number of H3 indices. (Int64)

Example:

SELECT h3NumHexagons(3) AS num_taco_zones;

Result:

| num_taco_zones |
|----------------|
| 41162          |

In this example, we calculate the number of unique H3 indices (potential taco delivery zones) at resolution 3. This could be useful for estimating the coverage of a taco delivery service at different granularities.

The number of hexagons increases significantly with each resolution level. Be cautious when using high resolutions, as it may result in a very large number of hexagons.

h3PointDistM

Calculates the “great circle” or “haversine” distance between two geographic points in meters.

Syntax:

h3PointDistM(lat1, lon1, lat2, lon2)

Arguments:

  • lat1, lon1 (Float64): Latitude and longitude of the first point in degrees.
  • lat2, lon2 (Float64): Latitude and longitude of the second point in degrees.

Returns:

  • The great circle distance between the two points in meters. (Float64)

Example:

SELECT
	h3PointDistM(37.7749, -122.4194, 34.0522, -118.2437) AS distance_sf_to_la;

Result:

| distance_sf_to_la |
|-------------------|
| 559121.2072607822 |

This example calculates the distance in meters between San Francisco (Taco Town) and Los Angeles (Burrito City).

This function is particularly useful for calculating distances between taco trucks or restaurants in different cities.

h3PointDistKm

Calculates the “great circle” or “haversine” distance between two geographic points on Earth in kilometers.

Syntax:

h3PointDistKm(lat1, lon1, lat2, lon2)

Arguments:

  • lat1, lon1 (Float64): Latitude and longitude of the first point in degrees.
  • lat2, lon2 (Float64): Latitude and longitude of the second point in degrees.

Returns:

The great circle distance between the two points in kilometers. (Float64)

Example:

SELECT
	h3PointDistKm(37.7749, -122.4194, 34.0522, -118.2437) AS distance_sf_to_la;

Result:

| distance_sf_to_la |
|-------------------|
| 559.1212072607823 |

This example calculates the distance between San Francisco (Taco Town) and Los Angeles (Burrito City) in kilometers.

The function uses the Earth’s mean radius for calculations. For very precise measurements or for locations near the poles, consider using more specialized geodesic functions.

h3PointDistRads

Returns the “great circle” or “haversine” distance between pairs of geographic coordinates in radians.

Syntax:

h3PointDistRads(lat1, lon1, lat2, lon2)

Arguments:

  • lat1, lon1 (Float64): Latitude and longitude of the first point in degrees.
  • lat2, lon2 (Float64): Latitude and longitude of the second point in degrees.

Returns:

  • The great circle distance between the two points in radians. (Float64)

Example:

SELECT
  h3PointDistRads(37.7749, -122.4194, 34.0522, -118.2437) AS taco_distance;

Result:

| taco_distance         |
|-----------------------|
| 0.08776025381597148   |

In this example, we calculate the distance in radians between San Francisco (the taco capital of the Bay Area) and Los Angeles (home of the famous Korean taco trucks).

This function is useful for calculating distances on a spherical surface, such as Earth, without the need for unit conversion. It’s particularly handy when working with H3 indexes or other geospatial applications where radian measurements are preferred.

h3GetRes0Indexes

Returns an array of all the resolution 0 H3 indexes.

Syntax:

h3GetRes0Indexes()

Returns:

Array of all the resolution 0 H3 indexes. [Array(UInt64)]

Example:

SELECT h3GetRes0Indexes() AS taco_zones;

Result:

| taco_zones                                        |
|---------------------------------------------------|
| [576495936675512319,576531121047601151,...(122)]  |

In this example, h3GetRes0Indexes() returns an array of 122 UInt64 values representing all the base (resolution 0) H3 cells. These could be thought of as the largest possible “taco delivery zones” in a global H3-based delivery system.

The resolution 0 indexes represent the coarsest division of the Earth’s surface in the H3 system, with each cell covering approximately 4,250,546.8 km² (about 7.81% of the Earth’s surface).

h3GetPentagonIndexes

Returns all the pentagon H3 indexes at the specified resolution.

Syntax:

h3GetPentagonIndexes(resolution)

Arguments:

  • resolution (UInt8): Index resolution. Range: [0, 15].

Returns:

Array of all pentagon H3 indexes. [Array(UInt64)]

Example:

SELECT h3GetPentagonIndexes(3) AS pentagon_indexes;

Result:

| pentagon_indexes                                                    |
|---------------------------------------------------------------------|
| [590112357393367039,590464201114255359,590816044835143679,...]      |

In this example, we retrieve all pentagon H3 indexes at resolution 3. The result is an array of UInt64 values representing the pentagon indexes.

Pentagon indexes are special cases in the H3 grid system, occurring 12 times per resolution (once per face of the icosahedron). They are important for certain geospatial calculations and analyses.

Here’s the updated markdown with the requested changes:

h3Line

Returns the line of H3 indices between two given H3 indices.

Syntax:

h3Line(start, end)

Arguments:

  • start (UInt64): The H3 index of the starting point.
  • end (UInt64): The H3 index of the ending point.

Returns:

An array of H3 indices representing the line between the start and end points. [Array(UInt64)]

Example:

SELECT
	h3Line(geoToH3(37.7752, -122.4185, 9), geoToH3(37.7858, -122.4089, 9)) AS taco_delivery_route;

Result:

| taco_delivery_route                                                                                                                    |
|----------------------------------------------------------------------------------------------------------------------------------------|
| [617700169958293503,617700169958293505,617700169958293507,617700169958293509,617700169958293511,617700169958293513,617700169958293515] |

This example calculates a route for taco delivery between two locations in San Francisco, represented by their H3 indices.

The function returns the shortest path between two H3 indices. It’s useful for routing and distance calculations in geospatial applications.

h3Distance

Calculates the distance in grid cells between two H3 indexes.

Syntax:

h3Distance(start, end)

Arguments:

  • start (UInt64): The starting H3 index.
  • end (UInt64): The ending H3 index.

Returns:

  • The number of grid cells between the two indexes. [Int64]
  • Returns a negative number if finding the distance fails.

Example:

SELECT
	h3Distance(
		geoToH3(37.7752, -122.4185, 9),  -- Taco stand location
		geoToH3(37.7792, -122.4194, 9)   -- Nearby taco truck
	) AS taco_distance;

Result:

| taco_distance |
|---------------|
| 3             |

In this example, we calculate the distance between a Taco Stand location and a nearby taco truck using their H3 indexes at resolution 9. The result shows they are 3 grid cells apart.

The h3Distance function is useful for quickly estimating distances between locations without the need for precise geographic calculations. It’s particularly efficient for proximity searches and clustering analysis in location-based applications.

Here’s the updated markdown with the requested changes:

h3HexRing

Returns the indexes of the hexagonal ring centered at the provided origin H3 index and with the specified length k.

Syntax:

h3HexRing(index, k)

Arguments:

  • index (UInt64): H3 index representing the origin.
  • k (UInt64): Distance from the origin.

Returns:

  • Array of H3 indexes representing the hexagonal ring. [Array(UInt64)]

Example:

SELECT
  h3HexRing(geoToH3(37.7752702151959, -122.418307270836, 9), CAST(1 AS UInt16)) AS taco_delivery_zone;

Result:

| taco_delivery_zone                                                                                                 |
|--------------------------------------------------------------------------------------------------------------------|
| [617700169958293503,617700169959342079,617700169964584959,617700169957244927,617700169955147775,617700169957244927]|

In this example, we define a taco delivery zone as a hexagonal ring around a central location in San Francisco. The result is an array of H3 indexes representing the perimeter of the delivery area, which could be used to determine eligible delivery addresses or calculate delivery fees.

If a pentagonal distortion is encountered, the function may return fewer than 6 * k indexes.

h3GetUnidirectionalEdge

Returns a unidirectional edge H3 index based on the provided origin and destination hexagons.

Syntax:

h3GetUnidirectionalEdge(originIndex, destinationIndex)

Arguments:

  • originIndex (UInt64): Origin hexagon index.
  • destinationIndex (UInt64): Destination hexagon index.

Returns:

  • Unidirectional edge H3 index (UInt64).
  • Returns 0 if the hexagons are not neighbors or if the input is invalid.

Example:

SELECT
  h3GetUnidirectionalEdge(599686042433355775, 599686043507097599) AS taco_delivery_route;

Result:

| taco_delivery_route |
|---------------------|
| 1248204388774707199 |

In this example, we calculate the unidirectional edge between two neighboring H3 indexes, which could represent a taco delivery route from one hexagon to another.

This function is useful for creating directed graphs of H3 cells, which can be used for routing or connectivity analysis in geospatial applications.

h3UnidirectionalEdgeIsValid

Determines if the provided H3 index is a valid unidirectional edge index.

Syntax:

h3UnidirectionalEdgeIsValid(index)

Arguments:

  • index (UInt64): H3 index number.

Returns:

  • 1 — The H3 index is a valid unidirectional edge. [UInt8]
  • 0 — The H3 index is not a valid unidirectional edge. [UInt8]

Example:

SELECT h3UnidirectionalEdgeIsValid(1248204388774707199) AS is_valid_edge;

Result:

| is_valid_edge |
|---------------|
| 1             |

In this example, we check if the given H3 index represents a valid unidirectional edge. The result 1 indicates that it is indeed a valid unidirectional edge.

This function is useful for validating H3 indexes when working with unidirectional edges in geospatial applications, such as routing or boundary analysis in taco delivery service areas.

h3GetOriginIndexFromUnidirectionalEdge

Returns the origin hexagon index from a given unidirectional edge H3 index.

Syntax

h3GetOriginIndexFromUnidirectionalEdge(edge)

Arguments

  • edge (UInt64): Hexagon index number representing a unidirectional edge.

Returns

  • Origin hexagon index number. (UInt64)

Example

SELECT h3GetOriginIndexFromUnidirectionalEdge(1248204388774707199) AS origin_index;

Result:

| origin_index       |
|--------------------|
| 599686042433355775 |

This example demonstrates how to get the origin hexagon index from a unidirectional edge in a taco delivery route optimization system. The origin index could represent the starting point of a delivery path between two adjacent hexagonal areas.

h3GetDestinationIndexFromUnidirectionalEdge

Returns the destination hexagon index from a unidirectional edge H3 index.

Syntax:

h3GetDestinationIndexFromUnidirectionalEdge(edge)

Arguments:

  • edge (UInt64): Hexagon index number representing a unidirectional edge.

Returns:

  • Destination hexagon index number. [UInt64]

Example:

SELECT h3GetDestinationIndexFromUnidirectionalEdge(1248204388774707197) AS destination_index;

Result:

| destination_index |
|-------------------|
| 599686043507097597|

This function is useful when working with H3 unidirectional edges, particularly in geospatial applications or routing algorithms. It allows you to extract the destination hexagon from an edge representation.

Ensure that the input is a valid unidirectional edge index. You can use h3UnidirectionalEdgeIsValid to check the validity of an edge index before using this function.

h3GetIndexesFromUnidirectionalEdge

Returns the origin and destination hexagon indexes from the given unidirectional edge H3 index.

Syntax:

h3GetIndexesFromUnidirectionalEdge(edge)

Arguments:

  • edge (UInt64): Hexagon index number that represents a unidirectional edge.

Returns:

A tuple consisting of two values tuple(origin, destination):

  • origin (UInt64): Origin hexagon index number.
  • destination (UInt64): Destination hexagon index number.

Returns (0, 0) if the provided input is not a valid unidirectional edge.

Example:

SELECT h3GetIndexesFromUnidirectionalEdge(1248204388774707199) AS taco_delivery_route;

Result:

| taco_delivery_route                         |
|---------------------------------------------|
| (599686042433355775, 599686043507097599)    |

In this example, we get the origin and destination hexagon indexes for a taco delivery route represented by a unidirectional edge. The result shows the starting point (origin) and ending point (destination) of the delivery route.

h3GetUnidirectionalEdgesFromHexagon

Returns all of the unidirectional edges originating from the provided H3 index.

Syntax:

h3GetUnidirectionalEdgesFromHexagon(index)

Arguments:

  • index (UInt64): H3 index of the origin hexagon.

Returns:

Array of H3 indexes representing each unidirectional edge originating from the given hexagon. [Array(UInt64)]

Example:

SELECT h3GetUnidirectionalEdgesFromHexagon(599686042433355775) AS taco_delivery_routes;

Result:

| taco_delivery_routes                                                                                                        |
|-----------------------------------------------------------------------------------------------------------------------------|
| [1248204388774707199,1320261982812635135,1392319576850563071,1464377170888491007,1536434764926418943,1608492358964346879]   |

In this example, we get all the unidirectional edges (potential taco delivery routes) from a specific H3 hexagon. Each edge represents a path to a neighboring hexagon, which could be used to plan efficient taco deliveries to adjacent areas.

This function is useful for analyzing connectivity and creating path-finding algorithms in hexagonal grid systems, such as optimizing delivery routes or planning service coverage areas.

h3GetUnidirectionalEdgeBoundary

Returns the coordinates defining the boundary of a unidirectional edge in the H3 grid system.

Syntax:

h3GetUnidirectionalEdgeBoundary(edge)

Arguments:

  • edge (UInt64): A unidirectional edge H3 index.

Returns:

  • An array of pairs (lon, lat) representing the boundary coordinates of the edge. [Array(Tuple(Float64, Float64))]

Example:

SELECT h3GetUnidirectionalEdgeBoundary(1248204388774707199) AS edge_boundary;

Result:

| edge_boundary                                                                           |
|-----------------------------------------------------------------------------------------|
| [(37.42012867767779,-122.03773496427027),(37.33755608435299,-122.090428929044)]         |

In this example, the function returns the coordinates of the start and end points of the unidirectional edge represented by the H3 index 1248204388774707199. These coordinates could be used for visualizing the edge on a map or for further geographical calculations.

This function is particularly useful when working with H3 edges in geospatial applications, allowing you to obtain the precise geographical boundaries of H3 grid edges.