# Seeking Python equivalent to h3_to_polygon of R [closed]

How do I convert H3 hex-ids (e.g., `'87422c2a9ffffff'`) to Polygon geometry using Python?

In R, we would use:

``````h3_to_polygon()
``````
• 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)`. Commented Jan 14, 2021 at 23:03

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]))
``````

There is a simple equivalent in python:

Assumptions:

• hexagonID: your pandas column name containing hexagon ids
• geometry: your geometry output column
``````
from shapely.geometry import Polygon
import h3

df["geometry"] = df["hexagonID"].apply(lambda x: Polygon(h3.h3_to_geo_boundary(x, geo_json=True)))

``````