Skip to main content

Offline fast reverse geocoding. Named after the Chinese Goddess of the Earth Houtu.

Project description

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.

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

houtu-0.0.3.tar.gz (6.2 MB view details)

Uploaded Source

Built Distribution

houtu-0.0.3-py3-none-any.whl (6.2 MB view details)

Uploaded Python 3

File details

Details for the file houtu-0.0.3.tar.gz.

File metadata

  • Download URL: houtu-0.0.3.tar.gz
  • Upload date:
  • Size: 6.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for houtu-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8e3a28c44f80ca928d16dfa15c443feb200262ab9e790d9519301a50ab7d36c1
MD5 6704ef56e0bc9402c11302f9e681cd78
BLAKE2b-256 fb858a6b7fdecb87c32de9b59304e2f2f24a85cdb8129c764b90f0f2d3a72144

See more details on using hashes here.

File details

Details for the file houtu-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: houtu-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for houtu-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 18249b967bfc4a21f0a0bb9f1bf532e90ab6732cf07424864772bf750fa0a6a6
MD5 3615e5adcdd554e0c465555750dcd0bd
BLAKE2b-256 01feba3f6bf5991a7e41bddcdc847f04eb70df4be0ec0db0b0b6cca149dac5d4

See more details on using hashes here.

Supported by

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