Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Last active April 22, 2022 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidpixo/353eca9752a6587156fa109f93a3b6c3 to your computer and use it in GitHub Desktop.
Save kidpixo/353eca9752a6587156fa109f93a3b6c3 to your computer and use it in GitHub Desktop.
# tested using https://github.com/uber/h3-py-notebooks/blob/master/notebooks/usage.ipynb
from h3 import h3
from shapely.geometry.polygon import Polygon
h3_list = [ Polygon(h3.h3_to_geo_boundary(he)) for he in h3.hex_ring(h,2)]
n = len(h3_list)
print(f'Polygon.exterior.is_closed = {h3_list[0].exterior.is_closed}')
import geopandas as gpd
gdf=gpd.GeoDataFrame(columns=['value'],data=range(len(h3_list)),geometry=h3_list)
import matplotlib.cm as cm
gdf['color_rgba'] = gdf.apply(lambda row: cm.Spectral(row['value']/n), axis=1)
gdf.plot(color=gdf['color_rgba'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment