Skip to content

generate H3 hexgrids as GeoJSON for a region using WOF IDs

License

Notifications You must be signed in to change notification settings

burritojustice/wof2h3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wof2h3

This node.js script takes a Who's On First identifier and an H3 resolution as input and generates an H3 hexgrid that fills the geometry specified by the WOF ID (city, region, country, continent...) It saves the hexbin grid and their centroids to two GeoJSON files.

$ node wof2h3.mjs 85688637 5
WOF ID 85688637 California
1574 hexbins
$ node wof2h3.mjs 85688637 6
WOF ID 85688637 California
10997 hexbins
$ node wof2h3.mjs 85688637 7
WOF ID 85688637 California
77011 hexbins

(If you're not familiar with Who's On First it's an open source gazetteer with stable identifiers. For example, California is, and always will be 85688637. You can look up an WOF ID using the Spelunker.)

It generates two files named wofid_wofname_h3resolution_kind.geojson

california_h3_r5_hexbins california_h3_r5_centroids

The feature ID is the h3 index.

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "id": "852912dbfffffff",
      "properties": {
        "value": {
          "kind": "hexbin",
          "resolution": 5
        }
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -119.04393751440749,
              33.42244126143113
            ]...

You can then dig in using whatever GeoJSON tools you prefer, such as HERE Data Hub aka XYZ or Tangram and Space Invader or https://geojson.tool

If an alt_mapzen alternate geometry is available, it will be used instead of the default WOF geometry. (Sorry Farallons.)

What is this for?

I made this with the idea that high resolution H3 grids could be viewed at lower map zoom levels to create a dense dot density map or a pseudo heat map using intersections, or joins on the H3 IDs. It's also interesting to see how h3 hexbins stack at different resolutions.

germany r4,5,6 link

h3 viridis

And the h3 grid makes much more sense when you don't use web mercator

north america space invader globe

But it also looks cool as just a space-filling pattern.

us colors

Issues:

  • geojson2h3.featureToH3Set only returns hexagons where the centroid falls within the provided polygon. While this makes sense when you have neighboring polygons, it would be nice to get all hexagons that touch a stand-alone polygon (if that's how you roll). h3.polyfill returns an outline of the perimeter of the polygon, so maybe you could traverse that set and check if any of their edges are inside the source polygon?

Questions:

I don't really know what I'm doing with node and got this to work through brute force and desperation and coffee and IPA. A few questions:

  • Why did I need to .mjs and import instead of const?
  • How do I package this so you don't have to run around and grab dependencies?

dependencies

About

generate H3 hexgrids as GeoJSON for a region using WOF IDs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published