Skip to main content

Lightweight reverse geolocation

Project description

LocatePy

LocatePy is a lightweight, fast reverse-geolocation utility for Python.
It maps latitude/longitude coordinates to administrative boundaries using a prebuilt SQLite database with R-Tree spatial indexing and compressed WKB geometries for exact geometry verification.

This project is designed to be:

  • Fast — minimal dependencies, only Shapely
  • Lightweight — SQLite + compressed geometries
  • Offline-first — no API calls, no internet required

Features

  • Reverse geolocation from (lat, lon)Country / District / Municipal
  • Spatial lookup via SQLite R-Tree
  • Geometry checks powered by Shapely
  • Compressed WKB for efficient storage
  • Simple API
  • Data for geolocation provided by geoboundaries.org

Usage

Basic Example

from locatepy.locatepy import LocatePy

locator = LocatePy()
result = locator.locate(lat=43.6532, lon=-79.3832)

print(result.country) # Canada
print(result.district) # Ontario
print(result.municipal) # Toronto

Returned Object

locate() returns a LocateResult dataclass:

LocateResult(
    country: str,    # ADM0
    district: str,   # ADM1
    municipal: str   # ADM2
)

If no match is found:

LocateResult("UNKNOWN", "UNKNOWN", "UNKNOWN")

Installation

pip install locatepy

Dependencies

LocatePy requires:

  • Python 3.9+
  • shapely
  • Ships with a prebuilt SQLite database

Geometry Storage

  • Municipal geometries stored as zlib-compressed WKB
  • Bounding boxes stored in the R-Tree (minx, maxx, miny, maxy)

How It Works

  1. A Point(lon, lat) is created using Shapely
  2. The SQLite R-Tree is queried for candidate municipalities
  3. Candidate geometries are:
    • Decompressed from zlib
    • Loaded from WKB
  4. A precise shapely covers test determines containment
  5. The matching admin hierarchy is returned

This approach avoids expensive full-table scans and keeps memory usage low.

Performance Notes

  • R-Tree bounding box filtering reduces geometry checks dramatically
  • Geometry decompression occurs only for candidate matches
  • No internet connection required

Limitations

  • Resolution and accuracy depend entirely on the source boundary data provided by geoboundaries.org
  • Does not currently support:
    • Reverse geocoding to street/address level
    • Multi-match results
    • Assumes WGS84

License

MIT License

LocatePy — simple, fast, offline reverse geolocation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

locatepy-1.0.0.tar.gz (79.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

locatepy-1.0.0-py3-none-any.whl (79.9 MB view details)

Uploaded Python 3

File details

Details for the file locatepy-1.0.0.tar.gz.

File metadata

  • Download URL: locatepy-1.0.0.tar.gz
  • Upload date:
  • Size: 79.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for locatepy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7189c78984a394434e5b753731cd4b91dd57a844bfcc652c5beeef0a6730f393
MD5 d556265f924c22a1b4d7535b1de7c437
BLAKE2b-256 3e66145420dd129534049bbb005b014c27a5669fbb8f8679a77d9b4ec091273f

See more details on using hashes here.

File details

Details for the file locatepy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: locatepy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 79.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for locatepy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95b35ae97117520c0337441a827a945963184ebad1420767ab7990dd9ff528fd
MD5 1b7d40dc6b31919fb8a9fa0b3c486eeb
BLAKE2b-256 3fec2d2a2d263bb6bedae07dea6ad4173dad414f39ed89efa451403782944951

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page