Skip to content

h3

h3(function_name, arguments)

Description

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

Usage

Call or Deploy h3 ?
Call h3 directly

The easiest way to use bigfunctions

  • h3 function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy h3 in your project

Why deploy?

  • You may prefer to deploy h3 in your own project 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).
  • Get started by reading the framework page

Deployment

h3 function can be deployed with:

pip install bigfunctions
bigfun get h3
bigfun deploy h3

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" |
+-------------------+

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.


Need help or Found a bug?
Get help using h3

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about 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.

We also provide professional suppport.


Show your ❤ by adding a ⭐ on