houtu
Offline fast reverse geocoding. Named after the Chinese Goddess of the Earth Houtu.
Various implementations are included.
- Naive computation of haversine distance matrix. Coordinates are not converted.
- Using ball-tree with haversine metric. Coordinates are not converted.
- Naive computation of Euclidean distance matrix. Coordinates are converted from geodetic to ECEF and back.
- Using kd-tree with Euclidean metric. Coordinates are converted from geodetic to ECEF and back.
Install
- requires Python 3.8+
- run
pip install houtu
Use
import numpy as np
from houtu import ReverseGeocode
rg = ReverseGeocode()
arr = np.array([
[25.04776, 121.53185], # taipei
[48.13743, 11.57549], # munich
], dtype=np.float32)
coords, distances, cities = rg.query(arr, k=2, form="degrees")
print(cities)
Output
[[
City(name='Taipei', feature_class='P', feature_code='PPLC', country_code='TW', admin1_code='04', admin2_code='TPE', admin3_code='', admin4_code='', population=7871900, elevation=None, timezone='Asia/Taipei'),
City(name='Neihu', feature_class='P', feature_code='PPL', country_code='TW', admin1_code='04', admin2_code='TPE', admin3_code='A14', admin4_code='63000100010', population=271594, elevation=None, timezone='Asia/Taipei')
], [
City(name='Munich', feature_class='P', feature_code='PPLA', country_code='DE', admin1_code='02', admin2_code='091', admin3_code='09162', admin4_code='09162000', population=1260391, elevation=None, timezone='Europe/Berlin'),
City(name='Bogenhausen', feature_class='P', feature_code='PPLX', country_code='DE', admin1_code='02', admin2_code='091', admin3_code='09162', admin4_code='09162000', population=77542, elevation=None, timezone='Europe/Berlin')
]]
Benchmark
Batch of 2
| class | time/s |
|---|---|
| ReverseGeocodeBruteHaversine | 35.674 |
| ReverseGeocodeBallHaversine | 0.192 |
| ReverseGeocodeBruteEuclidic | 22.110 |
| ReverseGeocodeKdLearn | 0.392 |
| ReverseGeocodeKdScipy | 0.317 |
Batch of 100
| class | time/s |
|---|---|
| ReverseGeocodeBruteHaversine | 193.119 |
| ReverseGeocodeBallHaversine | 0.918 |
| ReverseGeocodeBruteEuclidic | 86.881 |
| ReverseGeocodeKdLearn | 0.122 |
| ReverseGeocodeKdScipy | 0.095 |
Optimize
vincenty haversine
mean_absolute_error IUGG radius of sphere of same volume (R3) 897.7743386541117
mean_relative_error Spherical Earth Approx. of Radius (RE) 0.0018409171841267883
geodesic haversine
mean_absolute_error IUGG radius of sphere of same volume (R3) 897.7743386541117
mean_relative_error Spherical Earth Approx. of Radius (RE) 0.0018409171841267883
vincenty euclidic {'mean_absolute_error': 976.6828669488417, 'mean_relative_error': 0.0006505034968118167}
geodesic euclidic {'mean_absolute_error': 976.628990753796, 'mean_relative_error': 0.0006465253527447903}
Development
- run tests
python -m unittest discover -s tests
Sources
Cities database file houtu/data/cities1000.txt.xz is downloaded and recompressed from http://download.geonames.org/export/dump/cities1000.zip (Creative Commons Attribution 4.0 License).
GeoNames issues
There are about 50 pairs of cities which have the exact same coordinates, for example Fajã de Baixo and Rosto de Cão.
Metadata
Release files for houtu 0.0.3
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 |
|---|---|---|---|---|
| houtu-0.0.3.tar.gz | 6.2 MB | Without provenance | Details for houtu-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| houtu-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for houtu-0.0.3-py3-none-any.whl |
Total release size: 12.4 MB
Release files / houtu-0.0.3.tar.gz
| Download URL | houtu-0.0.3.tar.gz |
|---|---|
| Size | 6.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e3a28c44f80ca928d16dfa15c443feb200262ab9e790d9519301a50ab7d36c1
|
|
BLAKE2b-256 checksum How to use checksums |
fb858a6b7fdecb87c32de9b59304e2f2f24a85cdb8129c764b90f0f2d3a72144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / houtu-0.0.3-py3-none-any.whl
| Download URL | houtu-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18249b967bfc4a21f0a0bb9f1bf532e90ab6732cf07424864772bf750fa0a6a6
|
|
BLAKE2b-256 checksum How to use checksums |
01feba3f6bf5991a7e41bddcdc847f04eb70df4be0ec0db0b0b6cca149dac5d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for houtu 0.0.3
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.