Skip to main content

world geohash index

Project description

worldgeo

World geohash index

A simple, easy to use python package to get a country by a given geohash or raw coordinates.

Getting started

Installation

pip install worldgeo

Usage

Import the Index class and load an index file (we'll discuss how to get one later on)

from worldgeo import Index
i = Index.load("world5.idx")

Now you can resolve a geohash

In [3]: i.find_by_hash("9smk")
Out[3]: 'MEX'

or coordinates

In [4]: i.find_by_coord(49.2827, -123.1207) # Vancouver
Out[4]: 'CAN'

Using a pre-built index

There are pre-built indexes based on https://github.com/johan/world.geo.json/blob/master/countries.geo.json . Given that, you don't really need to build indexes yourself, as there are ready to use files built by GitHub CI.

Pre-built indexes have various precision, check out the contents of prebuilt folder of this repo. Precision 6 means accuracy up to 1.2x1.2 km, which must be enough given the source might be even less accurate. Since more accurate index take much more disk and memory space, you might want to use precision 4 or 5 (39km or 5km correspondingly) as these take only a few Mb. Higher precision (7 and above) gives an index that is too large to fit in a default github repo, thus ShardedIndex was introduced. ShardedIndex splits the data into multiple files and can load them in parallel using multiprocessing.

Pre-built indexes can be loaded with a short-cut method load_prebuilt that takes an index name and a precision value. Available index names are world and vatsim. The world one resolves to a country alpha3 code and vatsim resolves to a region ICAO.

from worldgeo import Index

i = Index.load_prebuilt("vatsim", 5)
print(i.find_by_hash("ez656"))

The code above would resolve into LPPC-E which represents Lisboa FIR.

Building a new index

In case you still want to build a more (or less) precise index, you can do so by running

build-geoidx -o <output filename> -p <precision> [-t <num threads>] [-m] [-s]

and load the resulting file later on with Index.load(filename)

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

worldgeo-1.3.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

worldgeo-1.3.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file worldgeo-1.3.2.tar.gz.

File metadata

  • Download URL: worldgeo-1.3.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for worldgeo-1.3.2.tar.gz
Algorithm Hash digest
SHA256 13fb99bc714ac7a10442e61d63a421170cb2156fbe86005aa5fc6e05b07b1fa5
MD5 ed635c23c2552b8e9dcd30829fb9b8ba
BLAKE2b-256 32a1f54eaeb302def677eb6f36d6461f6ecf499ac36a0f86a653b181badc9b60

See more details on using hashes here.

File details

Details for the file worldgeo-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: worldgeo-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for worldgeo-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7ccf96273e443050a70084c8965bea893ae0c12358d7c07b341f314dc6c4c814
MD5 f0b0bc4946074cd2557b7d17c9811f52
BLAKE2b-256 d626675ea0bfe67e864486f70cac9660b7cef62dc8ae00976a5e797a977ad669

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