geohash-python


Namegeohash-python JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/alitrack/geohash-python
SummaryA Python implementation of the Geohash algorithm compatible with python-geohash
upload_time2024-11-24 14:49:30
maintainerNone
docs_urlNone
authorSteven Lee
requires_python>=3.6
licenseNone
keywords geohash geo spatial location uint64 gis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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: list of 8 neighboring geohashes in the order [west, east, south, south-west, south-east, north, north-west, north-east]

#### expand(hashcode)
Alias for neighbors() - returns all 8 adjacent geohashes
- Parameters:
  - hashcode: str, geohash string
- Returns: list of 8 neighboring geohashes in the order [west, east, south, south-west, south-east, north, north-west, north-east]

#### 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/89/ba/d70f0f68d7a7c32529a9095e7d82913cac4ed0f5d67c8ea2fac5ebb21c74/geohash_python-0.1.0.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: list of 8 neighboring geohashes in the order [west, east, south, south-west, south-east, north, north-west, north-east]\n\n#### expand(hashcode)\nAlias for neighbors() - returns all 8 adjacent geohashes\n- Parameters:\n  - hashcode: str, geohash string\n- Returns: list of 8 neighboring geohashes in the order [west, east, south, south-west, south-east, north, north-west, north-east]\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.1.0",
    "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": "0ede65ae76759620c54f58a82e57e939c4cb9fb1ad5cd5b3078fa9fd58e56386",
                "md5": "22e67bc4bfc1aa9c316a930d78a5674e",
                "sha256": "9aa9d0d6b86650ad3b85f0be95ad5baa706a5f7579675ec18c4fc81e56bcfab6"
            },
            "downloads": -1,
            "filename": "geohash_python-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "22e67bc4bfc1aa9c316a930d78a5674e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8196,
            "upload_time": "2024-11-24T14:49:28",
            "upload_time_iso_8601": "2024-11-24T14:49:28.454243Z",
            "url": "https://files.pythonhosted.org/packages/0e/de/65ae76759620c54f58a82e57e939c4cb9fb1ad5cd5b3078fa9fd58e56386/geohash_python-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "89bad70f0f68d7a7c32529a9095e7d82913cac4ed0f5d67c8ea2fac5ebb21c74",
                "md5": "850857a12289412e17e8a83b0b4f8ebd",
                "sha256": "9aab380b243204edc9840b56005bf2dacf6bbb94e068e5698d6673a72b7a451f"
            },
            "downloads": -1,
            "filename": "geohash_python-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "850857a12289412e17e8a83b0b4f8ebd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7214,
            "upload_time": "2024-11-24T14:49:30",
            "upload_time_iso_8601": "2024-11-24T14:49:30.321426Z",
            "url": "https://files.pythonhosted.org/packages/89/ba/d70f0f68d7a7c32529a9095e7d82913cac4ed0f5d67c8ea2fac5ebb21c74/geohash_python-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-24 14:49:30",
    "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"
}
        
Elapsed time: 0.36054s