Python Geohash (Legacy)

0.8.5 · abandoned · verified Sat Apr 11

This is a legacy version (0.8.5) of a Python library for fast and accurate geohashing, providing functions to encode and decode geohashes to and from latitude/longitude coordinates. It originated from a Google Code project and was last updated in 2014. For actively maintained geohashing functionality, consider the 'pygeohash' library.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to encode latitude and longitude coordinates into geohash strings, control the precision, and decode geohash strings back into coordinates using the `geohash` module. It also shows the usage of `uint64` representation for integer-based geohashing.

import geohash

# Encode coordinates to a geohash string with default precision (12 characters)
latitude, longitude = 42.6, -5.6
geohash_string = geohash.encode(latitude, longitude)
print(f"Encoded geohash: {geohash_string}")

# Encode with custom precision
short_geohash = geohash.encode(latitude, longitude, precision=5)
print(f"Short geohash (precision 5): {short_geohash}")

# Decode a geohash string back to coordinates
decoded_lat, decoded_lng = geohash.decode(geohash_string)
print(f"Decoded coordinates: ({decoded_lat}, {decoded_lng})")

# Example with uint64 representation
uint64_hash = geohash.encode_uint64(latitude, longitude)
print(f"Encoded uint64 geohash: {uint64_hash}")
decoded_lat_uint64, decoded_lng_uint64 = geohash.decode_uint64(uint64_hash)
print(f"Decoded uint64 coordinates: ({decoded_lat_uint64}, {decoded_lng_uint64})")

view raw JSON →