2

I want to plot H3 hexagons. Of Austria.

Download and unzip https://biogeo.ucdavis.edu/data/gadm3.6/gpkg/gadm36_AUT_gpkg.zip

The full code is available at https://gist.github.com/geoHeil/b5b74887e20e4b659d4bb693a700a402 generates to generate hexagons like:

size = 7
hexagons = pd.DataFrame(h3.polyfill(geoJson, size), columns=['hexagons'])
hexagons.head()

8752e5b80ffffff
8752ee6c1ffffff

Note h3 expects epsg:4326 and later generates the same projection again (https://github.com/uber/h3/issues/121)

This gives a file similar to: enter image description here

Now when moving to https://kepler.gl/ and uploading the data I see three strange things happening

  1. polygons from the WKT line string are distorted. This would indicate that the wrong projection is used. But trying to convert to the supported https://github.com/keplergl/kepler.gl/blob/6b380ac6db94e10fed0a76f5e78ef7e55406df21/docs/user-guides/b-kepler-gl-workflow/a-add-data-to-the-map.md Webmercator does not fix it

enter image description here

  1. when manually adding a hexagon layer it is rendered in yemen (based on the H3 addr. This seems strange. Could this be a bug in kepler demo? enter image description here. This seems really weird as the geometries are generated out of the hexagons using: h3_to_geo_boundary

  2. hexagon centroids are not filled. Now when converting to hexagon centroids using h3_to_geo, and adding the data back in as ha HexBinlayer not all the hexagons are filled. But that is strange as originally all hexagons were available (see 1 and 2). enter image description here

notice how in (3) the hexbin hexagons are projected correctly as hexagons and not distorted.

Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
  • Hi, Georg! Have you managed to project H3 hexagons to Austria without shape distortion? I cannot manage to make them look as regular hexagons unless I use EPSG:4326, which distorts the shape of the country. Otherwise the hexagons always look stretched towards poles. – evnica Oct 12 '20 at 07:52
  • No. Please see: ` generated Cartesian north/south aligned hex grid, which is why they look "correct" on screen` maybe this helps (from the answer below – Georg Heiler Oct 12 '20 at 10:20

2 Answers2

2

I think there are a few things going on here:

  • Assuming you're using the master branch of h3-py, the signature of polyfill is polyfill(geo_json, res, geo_json_conformant=False). You need to add geo_json_conformant=True to your polyfill call, or the coords in your polygon will be interpreted as lat,lng instead of lng,lat. That's probably the source of your issues.

  • I'm not a Kepler expert, but I believe that the HexBin layer is using a generated Cartesian north/south aligned hex grid, which is why they look "correct" on screen. H3 hexagons have low distortion, but they do have some shape and area distortion, and they are never north/south aligned. When you display them with a Mercator projection, as in Kepler, they will have even more distortion, especially toward the poles, as a function of the projection. However, the main distortion issue here is probably due to switching lat,lng - the h3_to_multi_polygon function also requires an extra boolean argument to output GeoJSON-conformant coords.

  • I believe that Kepler also supports an H3 hexagon layer, so one option is to feed the raw points into Kepler and let Kepler do the aggregation to H3 indexes.

nrabinowitz
  • 55,314
  • 10
  • 149
  • 165
  • Hi, indeed your last point is correct. I tried this. See my second point. This resulted in a swap of lat/long for the kepler interpreted H3 addresses. I was on the last pipi version, but I can try master as well. But I tried the latest kepler master - there it also still failed. – Georg Heiler Nov 07 '19 at 17:46
  • Indeed, when using this option correct hexagons are generated when using the H3 layer. – Georg Heiler Nov 07 '19 at 18:01
  • Interestingly, in this new version, the `geometry` field containing WKT breaks kepler itself. – Georg Heiler Nov 07 '19 at 18:10
0

kepler uses an instance rendering on all hexagons, it assumes all your h3 hexagons are relatively close to each other. It uses your current map center to calculate hexagon distortion and apply it to all hexagons (instance rendering). Not perfect but significantly improves performance. Because it is too costly to calculate distortion for each hexagon.

ShanH
  • 11
  • 1