Created
January 8, 2026 15:49
-
-
Save bnaul/d4d3e651ffd9a81f7e42bc623860a9fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION bqutils.geo.H3_FROMLONGLAT(longitude FLOAT64, latitude FLOAT64, resolution INT64) | |
| RETURNS STRING | |
| LANGUAGE js | |
| OPTIONS ( | |
| library = ["https://storage.googleapis.com/bqutils.replicahq.com/h3-js.min.js"], | |
| description = """Converts a longitude/latitude pair to an H3 cell index at the specified resolution. | |
| Example usage: | |
| SELECT bqutils.geo.H3_FROMLONGLAT(-122.4194, 37.7749, 9) as h3_index; | |
| Output: | |
| "8928308280fffff" | |
| Parameters: | |
| - longitude: The longitude coordinate (FLOAT64) | |
| - latitude: The latitude coordinate (FLOAT64) | |
| - resolution: The H3 resolution (0-15, where 0 is coarsest and 15 is finest) | |
| Returns: | |
| The H3 cell index as a hexadecimal string, or null if inputs are invalid.""" | |
| ) | |
| AS r""" | |
| try { | |
| return h3.latLngToCell(latitude, longitude, Number(resolution)); | |
| } catch (error) { | |
| return null; | |
| } | |
| """; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment