I am looking for a way to convert H3 hex-ids (e.g., '87422c2a9ffffff'
) to Polygon geometry. In R, we would use:
h3_to_polygon()
But I am having a hard time finding the equivalent in Python.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityHere is what I did to solve the problem. There appears to be no equivalent in Python.
# turn h3 hexs into geo. boundary
df['geometry'] = df["h3_hexs"].apply(lambda x: h3.h3_to_geo_boundary(h=x, geo_json=True))
# turn to Point
df['geometry'] = df['geometry'].apply(lambda x: [Point(x,y) for [x,y] in x])
# turn to Polygon
df['geometry'] = df['geometry'].apply(lambda x: Polygon([[poly.x, poly.y] for poly in x]))
Do you want the outline of each cell, or the unioned outline of the cluster? For the latter, you probably want h3.h3_set_to_multi_polygon(cells, geo_json=True)
.