Skip to content

bigfunctions > h3

h3

Call or Deploy h3 ?

✅ You can call this h3 bigfunction directly from your Google Cloud Project (no install required).

  • This h3 function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

h3(function_name, arguments)

Description

Wrapper around Uber H3 (A Hexagonal Hierarchical Geospatial Indexing System).

Examples

select bigfunctions.eu.h3('latLngToCell', json '[37.3615593, -122.0553238, 7]')
select bigfunctions.us.h3('latLngToCell', json '[37.3615593, -122.0553238, 7]')
select bigfunctions.europe_west1.h3('latLngToCell', json '[37.3615593, -122.0553238, 7]')
+-------------------+
| result            |
+-------------------+
| "87283472bffffff" |
+-------------------+

Need help using h3?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using h3?

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

For professional suppport, don't hesitate to chat with us.

Use cases

A use case for the h3 BigQuery function would be analyzing ride-sharing data. Imagine you have a table of ride-sharing trips with starting and ending GPS coordinates (latitude and longitude). You want to identify popular pickup and dropoff locations at different levels of granularity.

Here's how you could use the h3 function:

  1. Convert GPS coordinates to H3 indexes: Use the latLngToCell function within h3 to convert each ride's start and end coordinates into H3 indexes at a specific resolution. The resolution controls the size of the hexagonal grid cells. A higher resolution (e.g., 10) means smaller, more precise cells, while a lower resolution (e.g., 6) means larger, more generalized cells.

SELECT
    trip_id,
    bigfunctions.<your-region>.h3('latLngToCell', JSON_ARRAY(start_lat, start_lng, 8)) AS start_h3,
    bigfunctions.<your-region>.h3('latLngToCell', JSON_ARRAY(end_lat, end_lng, 8)) AS end_h3
FROM
    `your_project.your_dataset.rides_table`;
Replace <your-region> with the appropriate BigQuery region (e.g., us, eu, us_central1).

  1. Aggregate trips by H3 index: Now you can group the trips by their start_h3 or end_h3 indexes to count the number of pickups or dropoffs within each hexagonal grid cell.
SELECT
    start_h3,
    COUNT(*) AS pickup_count
FROM (
    SELECT
        bigfunctions.<your-region>.h3('latLngToCell', JSON_ARRAY(start_lat, start_lng, 8)) AS start_h3
    FROM
        `your_project.your_dataset.rides_table`
)
GROUP BY
    start_h3
ORDER BY
    pickup_count DESC;
  1. Visualize the results: You can export the results to a visualization tool like GeoJSON.io or Kepler.gl. Since H3 indexes represent hexagons, you can easily display them on a map to visualize the density of ride-sharing activity in different areas. This allows you to identify hotspots, areas with high demand, or areas that might benefit from more drivers.

By using different H3 resolutions, you can analyze ride-sharing patterns at different scales. For example, a resolution of 8 might be suitable for identifying neighborhoods with high pickup activity, while a resolution of 6 could be used to analyze demand across larger districts or cities. The h3 function also provides other functionalities from the H3 library, such as finding neighboring cells (kRing), which can be useful for analyzing nearby areas or defining service zones.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on