Reputation: 148
I need code to decode geohash in python. There's a column which contains geohashes. I need them decoded into latitude and longitude.
Upvotes: 1
Views: 6295
Reputation: 43
this solution is performant:
import pygeohash
import numpy as np
def dehashingit(x):
"""
this returns a tuple, where at index 0 is the lats and at index 1 is the longs
"""
return pygeohash.decode(x)
func = np.vectorize(dehashingit)
location = func(df.geohash.values)
df['lat'], df['long'] = location[0], location[1]
Upvotes: 1
Reputation: 56
You can install pygeohash from pypi using pip
$ pip install pygeohash
Then add a new column to the dataframe with the latitude and longitude
import pygeohash as pgh
# ...
# location is a new column filled with (lat, lon) tuples
df['location'] = df.apply(lambda rec: pgh.decode(rec['geohash']), axis=1)
Here 'geohash'
is the column which contains geohashes.
Upvotes: 4