Reverse Geocode
Reverse Geocode takes a latitude / longitude coordinate and returns the nearest known country, state, and city. This can be useful when you need to reverse geocode a large number of coordinates so a web API is not practical.
The geocoded locations are from geonames. This data is then structured in to a k-d tree for efficiently finding the nearest neighbour.
Note that as this is point based and not a polygon based lookup it will only give a rough idea of the location/city.
Example usage
Example reverse geocoding a coordinate:
>>> import reverse_geocode
>>> melbourne_coord = -37.81, 144.96
>>> reverse_geocode.get(melbourne_coord)
{'country_code': 'AU', 'city': 'Melbourne', 'latitude': -37.814, 'longitude': 144.96332, 'population': 4917750, 'state': 'Victoria', 'country': 'Australia'}
Example reverse geocoding a list of coordinates:
>>> nyc_coord = 40.71427000, -74.00597000
>>> reverse_geocode.search((melbourne_coord, nyc_coord))
[{'country_code': 'AU', 'city': 'Melbourne', 'latitude': -37.814, 'longitude': 144.96332, 'population': 4917750, 'state': 'Victoria', 'country': 'Australia'},
{'country_code': 'US', 'city': 'New York City', 'latitude': 40.71427, 'longitude': -74.00597, 'population': 8804190, 'state': 'New York', 'country': 'United States'}]
By default the nearest known location is returned, which may not be as expected when there is a much larger city nearby. For example querying for the following coordinate near NYC will return Seaport:
>>> nyc_coordinate = 40.71, -74.00
>>> reverse_geocode.get(nyc_coordinate)
{'country_code': 'US', 'city': 'Seaport', 'latitude': 40.70906, 'longitude': -74.00317, 'population': 8385, 'state': 'New York', 'county': 'New York County', 'country': 'United States'}
To filter for larger cities a minimum population can be set. Using a minimum population of 100000 with the above coordinate now returns NYC:
>>> reverse_geocode.get(nyc_coordinate, min_population=100000)
{'country_code': 'US', 'city': 'New York City', 'latitude': 40.71427, 'longitude': -74.00597, 'population': 8804190, 'state': 'New York', 'country': 'United States'}
Install
pip install reverse-geocode
Metadata
Release files for reverse-geocode 1.6.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| reverse_geocode-1.6.6.tar.gz | 3.5 MB | Without provenance | Details for reverse_geocode-1.6.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| reverse_geocode-1.6.6-py3-none-any.whl | Python 3 | none | any | Details for reverse_geocode-1.6.6-py3-none-any.whl |
Total release size: 6.9 MB
Release files / reverse_geocode-1.6.6.tar.gz
| Download URL | reverse_geocode-1.6.6.tar.gz |
|---|---|
| Size | 3.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14165815816cc639dd74eb660a74e464aeebcd1d0814de74a897d62071c99f2a
|
|
BLAKE2b-256 checksum How to use checksums |
baa6be1e9403cd4b668ff2ec7fd532b534f8f4b31e62637ce7476fbb20ae1b37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / reverse_geocode-1.6.6-py3-none-any.whl
| Download URL | reverse_geocode-1.6.6-py3-none-any.whl |
|---|---|
| Size | 3.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f639fdb99cc88c08d2ffaf39dfb1eb5a0ecc2860c50288c4613eea30826d6a9f
|
|
BLAKE2b-256 checksum How to use checksums |
95948df60b4efe9edc8934218bac4764024ac423d2a2ed082bd0eb48d9321fe6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for reverse-geocode 1.6.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.