Fast offline reverse geocoding using a prepared Natural Earth cache
Project description
Reverse Geocoder
Tiny offline reverse geocoding for Python.
offlineRevGeocoder takes a latitude and longitude and returns a small GeoResult
object with the matching country, continent, ocean, and nearest city when one is
close enough. It is intentionally simple: the geographic source data is prepared
ahead of time, cached as a pickle file, and loaded locally at runtime. No API
keys, no network requests, no external service latency.
The bundled lookup data is derived from Natural Earth, a public domain map dataset. The prepared cache is included so callers can use the package immediately.
Project Info
- PyPI package:
offlineRevGeocoder - Import package:
offlineRevGeocoder - Source code: github.com/aminjavadi02/reverseGeocoder-py
- License: MIT
- Author: AminJavadi
This is an open-source package. Bug reports, fixes, data improvements, and documentation updates are welcome; please open an issue or send a pull request on GitHub.
Install
pip install offlineRevGeocoder
Usage
from offlineRevGeocoder import get
result = get(35.6892, 51.3890)
print(result.country) # Iran
print(result.country_iso2) # IR
print(result.city) # Tehran
print(result.precision) # city
Common Use Case
This package is most useful when you only need a small reverse geocoding answer, for example checking whether a user's latitude and longitude are in or near a specific city. In that kind of flow, you often do not need to pay for a full reverse geocoding API subscription.
from offlineRevGeocoder import get
place = get(35.7000, 51.4000, city_radius_km=25)
print(place.city) # Tehran
print(place.precision) # city
print(place.city == "Tehran") # True
For a nearby-city check, use city_radius_km to control how strict the match
should be for your product.
Return Type
get(lat, lon, city_radius_km=50) returns:
GeoResult(
continent: str | None,
country: str | None,
country_iso2: str | None,
country_iso3: str | None,
ocean: str | None,
city: str | None,
city_distance_km: float | None,
precision: str,
)
precision is one of:
city: a nearby city was found.country: the point matched a country, but no nearby city was found.ocean: the point matched an ocean or marine area.none: no matching land or ocean feature was found.
Data
The package uses Natural Earth datasets that were transformed into a compact
pickle cache at offlineRevGeocoder/data/reverse_geocoder_cache.pkl. Natural Earth data is
public domain, so it can be redistributed with this MIT-licensed package.
The code is MIT licensed. Natural Earth requests attribution where possible; this README keeps that attribution with the package.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file offlinerevgeocoder-0.1.0.tar.gz.
File metadata
- Download URL: offlinerevgeocoder-0.1.0.tar.gz
- Upload date:
- Size: 6.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7428c4d802eda64b88b05107cbf8ef30a1640de9fdc0881f80793b5776821445
|
|
| MD5 |
cb09258cf1fab50f9bf4793551962dc7
|
|
| BLAKE2b-256 |
a35d7f22be55176157f9ed11264ca33f5382a6f3ef88522e7deb17392617f620
|
File details
Details for the file offlinerevgeocoder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: offlinerevgeocoder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
766131c26f9d3e0cf1225c1292708192c382af31b3f544092ec71a66553253b2
|
|
| MD5 |
d386ff2d775a56b39f367af82eff645d
|
|
| BLAKE2b-256 |
c64cf514c1329311bc319e6535a9068552b95cfe650070e9d1f872e8d1eea139
|