I have been looking for a efficient way to convert a set of geohashes into polygons in Python, besides sometimes I obtain multipolygons instead of polygons, probably because some inner geohashes are missing. I am currently using python-geohash and shapely and my approach consists in the following steps:
I convert each geohash into a polygon by extracting its corner coordinates.
def to_polygon(geohash): box = Geohash.bbox(geohash) return Polygon([(box['e'], box['n']), (box['w'], box['n']), (box['w'], box['s']), (box['e'], box['s'])])
Then I
map
over theiterable
of geohashes performing previous explained transformation.polygons = [to_polygon(geohash) for geohash in geohashes]
Finally, I combine all those polygons into a single one, by using polygon's method union.
polygon = functools.reduce(lambda a, b: a.union(b), polygons)
If the set of geohashes is around some thousands it may take few minutes.