# Python Geohash
A Python implementation of the Geohash algorithm compatible with [python-geohash](https://pypi.org/project/python-geohash/). This package provides functionality to encode and decode geohashes, as well as find neighboring geohashes. It supports both string-based and uint64-based geohash representations.
## Installation
```bash
pip install geohash-python
```
## Features
- Encode latitude/longitude to geohash
- Decode geohash to latitude/longitude
- Get neighboring geohashes
- Get bounding box for geohash
- Pure Python implementation
- uint64 geohash support for efficient storage and computation
## API Reference
### String-based Geohash Operations
#### encode(latitude, longitude, precision=12)
Encode a position to geohash string
- Parameters:
- latitude: float (-90.0 to 90.0)
- longitude: float (-180.0 to 180.0)
- precision: int, length of resulting geohash string (default: 12)
- Returns: str, geohash string
#### decode(hashcode)
Decode a geohash string to latitude/longitude
- Parameters:
- hashcode: str, geohash string
- Returns: tuple (latitude, longitude)
#### decode_exactly(hashcode)
Decode a geohash string to latitude/longitude with error margins
- Parameters:
- hashcode: str, geohash string
- Returns: tuple (latitude, longitude, latitude_error, longitude_error)
#### neighbors(hashcode)
Get all 8 adjacent geohashes
- Parameters:
- hashcode: str, geohash string
- Returns: dict with keys n,ne,e,se,s,sw,w,nw containing neighboring geohashes
#### expand(hashcode)
Alias for neighbors() - returns all 8 adjacent geohashes
- Parameters:
- hashcode: str, geohash string
- Returns: dict with keys n,ne,e,se,s,sw,w,nw containing neighboring geohashes
#### bbox(hashcode)
Get the bounding box of a geohash
- Parameters:
- hashcode: str, geohash string
- Returns: dict with keys n,s,e,w containing the bounds
### uint64-based Geohash Operations
#### encode_uint64(latitude, longitude)
Encode a position to 64-bit integer geohash
- Parameters:
- latitude: float (-90.0 to 90.0)
- longitude: float (-180.0 to 180.0)
- Returns: int, 64-bit unsigned integer geohash
#### decode_uint64(geohash_uint64)
Decode a 64-bit integer geohash to latitude/longitude
- Parameters:
- geohash_uint64: int, 64-bit unsigned integer geohash
- Returns: tuple (latitude, longitude)
#### expand_uint64(geohash_uint64)
Get ranges of adjacent geohashes as uint64 values
- Parameters:
- geohash_uint64: int, 64-bit unsigned integer geohash
- Returns: list of tuples [(min_hash1, max_hash1), (min_hash2, max_hash2), ...] representing ranges of neighboring geohashes
## Usage Examples
### String-based Geohash Operations
```python
import geohash
# Encode a location
lat, lon = 37.8324, -122.2715
hash = geohash.encode(lat, lon) # returns 12 character string
hash = geohash.encode(lat, lon, precision=6) # returns 6 character string
# Decode a geohash
lat, lon = geohash.decode(hash)
# Get exact decoding with error margins
lat, lon, lat_err, lon_err = geohash.decode_exactly(hash)
# Get bounding box
bbox = geohash.bbox(hash)
print(f"North: {bbox['n']}, South: {bbox['s']}, East: {bbox['e']}, West: {bbox['w']}")
# Get neighbors
neighbors = geohash.neighbors(hash)
print(f"North: {neighbors['n']}, Northeast: {neighbors['ne']}")
```
### uint64-based Geohash Operations
```python
import geohash
# Encode latitude/longitude to uint64 geohash
lat, lon = 37.8324, -122.2715
uint64_hash = geohash.encode_uint64(lat, lon)
# Decode uint64 geohash to latitude/longitude
lat, lon = geohash.decode_uint64(uint64_hash)
# Get neighbor ranges as uint64 values
neighbor_ranges = geohash.expand_uint64(uint64_hash)
for min_hash, max_hash in neighbor_ranges:
print(f"Range: {min_hash} to {max_hash}")
```
## uint64 Geohash Format
The uint64 geohash format uses a 64-bit unsigned integer to represent a geohash:
- 32 bits for longitude precision
- 32 bits for latitude precision
- Bits are interleaved: even bits for longitude, odd bits for latitude
- Provides approximately 0.5cm precision at the equator
Benefits of uint64 geohash:
- More efficient storage in databases
- Faster comparison operations
- Memory-efficient geospatial calculations
- Consistent precision across all locations
## License
MIT License
Raw data
{
"_id": null,
"home_page": "https://github.com/alitrack/geohash-python",
"name": "geohash-python",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "geohash, geo, spatial, location, uint64, gis",
"author": "Steven Lee",
"author_email": "alitrack.com@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a5/fc/845ed0e7cb98646b3c61fef3fd5f0737b5c07dc41b22b554588a6fe68012/geohash-python-0.8.5.tar.gz",
"platform": null,
"description": "# Python Geohash\n\nA Python implementation of the Geohash algorithm compatible with [python-geohash](https://pypi.org/project/python-geohash/). This package provides functionality to encode and decode geohashes, as well as find neighboring geohashes. It supports both string-based and uint64-based geohash representations.\n\n## Installation\n\n```bash\npip install geohash-python\n```\n\n## Features\n\n- Encode latitude/longitude to geohash\n- Decode geohash to latitude/longitude\n- Get neighboring geohashes\n- Get bounding box for geohash\n- Pure Python implementation\n- uint64 geohash support for efficient storage and computation\n\n## API Reference\n\n### String-based Geohash Operations\n\n#### encode(latitude, longitude, precision=12)\nEncode a position to geohash string\n- Parameters:\n - latitude: float (-90.0 to 90.0)\n - longitude: float (-180.0 to 180.0)\n - precision: int, length of resulting geohash string (default: 12)\n- Returns: str, geohash string\n\n#### decode(hashcode)\nDecode a geohash string to latitude/longitude\n- Parameters:\n - hashcode: str, geohash string\n- Returns: tuple (latitude, longitude)\n\n#### decode_exactly(hashcode)\nDecode a geohash string to latitude/longitude with error margins\n- Parameters:\n - hashcode: str, geohash string\n- Returns: tuple (latitude, longitude, latitude_error, longitude_error)\n\n#### neighbors(hashcode)\nGet all 8 adjacent geohashes\n- Parameters:\n - hashcode: str, geohash string\n- Returns: dict with keys n,ne,e,se,s,sw,w,nw containing neighboring geohashes\n\n#### expand(hashcode)\nAlias for neighbors() - returns all 8 adjacent geohashes\n- Parameters:\n - hashcode: str, geohash string\n- Returns: dict with keys n,ne,e,se,s,sw,w,nw containing neighboring geohashes\n\n#### bbox(hashcode)\nGet the bounding box of a geohash\n- Parameters:\n - hashcode: str, geohash string\n- Returns: dict with keys n,s,e,w containing the bounds\n\n### uint64-based Geohash Operations\n\n#### encode_uint64(latitude, longitude)\nEncode a position to 64-bit integer geohash\n- Parameters:\n - latitude: float (-90.0 to 90.0)\n - longitude: float (-180.0 to 180.0)\n- Returns: int, 64-bit unsigned integer geohash\n\n#### decode_uint64(geohash_uint64)\nDecode a 64-bit integer geohash to latitude/longitude\n- Parameters:\n - geohash_uint64: int, 64-bit unsigned integer geohash\n- Returns: tuple (latitude, longitude)\n\n#### expand_uint64(geohash_uint64)\nGet ranges of adjacent geohashes as uint64 values\n- Parameters:\n - geohash_uint64: int, 64-bit unsigned integer geohash\n- Returns: list of tuples [(min_hash1, max_hash1), (min_hash2, max_hash2), ...] representing ranges of neighboring geohashes\n\n## Usage Examples\n\n### String-based Geohash Operations\n\n```python\nimport geohash\n\n# Encode a location\nlat, lon = 37.8324, -122.2715\nhash = geohash.encode(lat, lon) # returns 12 character string\nhash = geohash.encode(lat, lon, precision=6) # returns 6 character string\n\n# Decode a geohash\nlat, lon = geohash.decode(hash)\n\n# Get exact decoding with error margins\nlat, lon, lat_err, lon_err = geohash.decode_exactly(hash)\n\n# Get bounding box\nbbox = geohash.bbox(hash)\nprint(f\"North: {bbox['n']}, South: {bbox['s']}, East: {bbox['e']}, West: {bbox['w']}\")\n\n# Get neighbors\nneighbors = geohash.neighbors(hash)\nprint(f\"North: {neighbors['n']}, Northeast: {neighbors['ne']}\")\n```\n\n### uint64-based Geohash Operations\n\n```python\nimport geohash\n\n# Encode latitude/longitude to uint64 geohash\nlat, lon = 37.8324, -122.2715\nuint64_hash = geohash.encode_uint64(lat, lon)\n\n# Decode uint64 geohash to latitude/longitude\nlat, lon = geohash.decode_uint64(uint64_hash)\n\n# Get neighbor ranges as uint64 values\nneighbor_ranges = geohash.expand_uint64(uint64_hash)\nfor min_hash, max_hash in neighbor_ranges:\n print(f\"Range: {min_hash} to {max_hash}\")\n```\n\n## uint64 Geohash Format\n\nThe uint64 geohash format uses a 64-bit unsigned integer to represent a geohash:\n- 32 bits for longitude precision\n- 32 bits for latitude precision\n- Bits are interleaved: even bits for longitude, odd bits for latitude\n- Provides approximately 0.5cm precision at the equator\n\nBenefits of uint64 geohash:\n- More efficient storage in databases\n- Faster comparison operations\n- Memory-efficient geospatial calculations\n- Consistent precision across all locations\n\n## License\n\nMIT License\n",
"bugtrack_url": null,
"license": null,
"summary": "A Python implementation of the Geohash algorithm compatible with python-geohash",
"version": "0.8.5",
"project_urls": {
"Bug Tracker": "https://github.com/alitrack/geohash-python/issues",
"Documentation": "https://github.com/alitrack/geohash-python",
"Homepage": "https://github.com/alitrack/geohash-python",
"Source Code": "https://github.com/alitrack/geohash-python"
},
"split_keywords": [
"geohash",
" geo",
" spatial",
" location",
" uint64",
" gis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "079a03dcce5fc96296aa0dde8766e20257fd750d01b5d90a00e9d2230d157ce6",
"md5": "af094adf7e4a2997de14409467ca7bc3",
"sha256": "4628852f1df4e8051305fea9fcd266f0d524c4d11900b558b5ac761bcd1b74b4"
},
"downloads": -1,
"filename": "geohash_python-0.8.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "af094adf7e4a2997de14409467ca7bc3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8026,
"upload_time": "2024-11-22T13:07:55",
"upload_time_iso_8601": "2024-11-22T13:07:55.171609Z",
"url": "https://files.pythonhosted.org/packages/07/9a/03dcce5fc96296aa0dde8766e20257fd750d01b5d90a00e9d2230d157ce6/geohash_python-0.8.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a5fc845ed0e7cb98646b3c61fef3fd5f0737b5c07dc41b22b554588a6fe68012",
"md5": "cab58e823173262d3f0c18d8afe1a47b",
"sha256": "df0f3998addf3f9fdc9b390c4757ff6c25615b68fad3f2ef136dfae1eb6e94e9"
},
"downloads": -1,
"filename": "geohash-python-0.8.5.tar.gz",
"has_sig": false,
"md5_digest": "cab58e823173262d3f0c18d8afe1a47b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 7102,
"upload_time": "2024-11-22T13:07:57",
"upload_time_iso_8601": "2024-11-22T13:07:57.258763Z",
"url": "https://files.pythonhosted.org/packages/a5/fc/845ed0e7cb98646b3c61fef3fd5f0737b5c07dc41b22b554588a6fe68012/geohash-python-0.8.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-22 13:07:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "alitrack",
"github_project": "geohash-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "geohash-python"
}