2

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.

2 Answers 2

2

Here 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]))
1

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.