Skip to content

Instantly share code, notes, and snippets.

@janbenetka
Last active October 27, 2022 10:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbenetka/efd717e908c18370d2dc9e777014c2e8 to your computer and use it in GitHub Desktop.
Save janbenetka/efd717e908c18370d2dc9e777014c2e8 to your computer and use it in GitHub Desktop.
[H3 hexagon functions in BigQuery] #h3 #hex
SELECT jslibs.h3.ST_GEOGPOINTFROMH3("u2ce02j")
SELECT jslibs.h3.ST_H3_BOUNDARY(jslibs.h3.ST_H3(ST_GEOGPOINT(13.377534960188237, 49.747300576525554), 11))
SELECT jslibs.h3.h3GetResolution("u2ce02j");
# lat/lon to hexagon
SELECT jslibs.h3.ST_H3(ST_GEOGPOINT(statistics.coordinate.longitude, statistics.coordinate.latitude), 10) AS dwell_hex_id,
WITH polygon AS (
SELECT
'POLYGON ((13.37722778320312 49.74609375, 13.37860107421875 49.74609375, 13.37860107421875 49.74746704101562, 13.37722778320312 49.74746704101562, 13.37722778320312 49.74609375))'
AS p)
SELECT ST_GEOGFROMTEXT(p) as geog , 'blue' as color FROM polygon
---------------------------------------------------------------------------------------------------------------------------------------
--- Javascript
--- https://github.com/uber/h3-js
--- Tutorials: https://observablehq.com/@nrabinowitz/h3-tutorial-the-h3-js-library
h3.geoToH3(20, 123, 2)
h3.h3ToGeo("8928342e20fffff")
h3.h3ToGeoBoundary("8928342e20fffff")
h3.h3ToChildren("8928342e20fffff", 10)
h3.h3ToParent("8928342e20fffff", 7)
h3.kRing("8728342e2ffffff", 1)
h3.hexRing("8728342e2ffffff", 1)
h3.h3Distance("8728342e6ffffff", "8728342c4ffffff")
h3.polyfill([[[37,-122], [36, -121], [36, -123]]], 5)
h3.h3SetToMultiPolygon(["85291a6ffffffff", "85291a6bfffffff", "852834d3fffffff"])
h3
.h3IsValid(h3Index) ⇒ boolean
.h3IsPentagon(h3Index) ⇒ boolean
.h3IsResClassIII(h3Index) ⇒ boolean
.h3GetBaseCell(h3Index) ⇒ number
.h3GetFaces(h3Index) ⇒ Array.<number>
.h3GetResolution(h3Index) ⇒ number
.geoToH3(lat, lng, res) ⇒ H3Index
.h3ToGeo(h3Index) ⇒ Array.<number>
.h3ToGeoBoundary(h3Index, [formatAsGeoJson]) ⇒ Array.<Array.<number>>
.h3ToParent(h3Index, res) ⇒ H3Index
.h3ToChildren(h3Index, res) ⇒ Array.<H3Index>
.h3ToCenterChild(h3Index, res) ⇒ H3Index
.kRing(h3Index, ringSize) ⇒ Array.<H3Index>
.kRingDistances(h3Index, ringSize) ⇒ Array.<Array.<H3Index>>
.hexRing(h3Index, ringSize) ⇒ Array.<H3Index>
.polyfill(coordinates, res, [isGeoJson]) ⇒ Array.<H3Index>
.h3SetToMultiPolygon(h3Indexes, [formatAsGeoJson]) ⇒ Array.<Array.<Array.<Array.<number>>>>
.compact(h3Set) ⇒ Array.<H3Index>
.uncompact(compactedSet, res) ⇒ Array.<H3Index>
.h3IndexesAreNeighbors(origin, destination) ⇒ boolean
.getH3UnidirectionalEdge(origin, destination) ⇒ H3Index
.getOriginH3IndexFromUnidirectionalEdge(edgeIndex) ⇒ H3Index
.getDestinationH3IndexFromUnidirectionalEdge(edgeIndex) ⇒ H3Index
.h3UnidirectionalEdgeIsValid(edgeIndex) ⇒ boolean
.getH3IndexesFromUnidirectionalEdge(edgeIndex) ⇒ Array.<H3Index>
.getH3UnidirectionalEdgesFromHexagon(h3Index) ⇒ Array.<H3Index>
.getH3UnidirectionalEdgeBoundary(edgeIndex, [formatAsGeoJson]) ⇒ Array.<Array.<number>>
.h3Distance(origin, destination) ⇒ number
.h3Line(origin, destination) ⇒ Array.<H3Index>
.experimentalH3ToLocalIj(origin, destination) ⇒ CoordIJ
.experimentalLocalIjToH3(origin, coords) ⇒ H3Index
.pointDist(latlng1, latlng2, unit) ⇒ number
.cellArea(h3Index, unit) ⇒ number
.exactEdgeLength(edge, unit) ⇒ number
.hexArea(res, unit) ⇒ number
.edgeLength(res, unit) ⇒ number
.numHexagons(res) ⇒ number
.getRes0Indexes() ⇒ Array.<H3Index>
.getPentagonIndexes(res) ⇒ Array.<H3Index>
.degsToRads(deg) ⇒ number
.radsToDegs(rad) ⇒ number
.H3Index : string
.H3IndexInput : string | Array.<number>
.CoordIJ : Object
.UNITS : Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment