Skip to main content

Georeferencing large amounts of data for free.

Project description

Geolocate

Georeferencing large amounts of data for free.

Special thanks to @brunodepauloalmeida and the whole team for the contributions.

How?

It's using the very same API that Waze uses to georeference addresses before it finds the best route to that destination. It requires no API keys, works really well and has fairly high throughput.

In order to make this package extensible, there's an abstract class GeolocateEngine that defines the interface for the engines. This allows for the addition of new engines without having to modify the code.

How do I use it?

First you have to install the geolocate package for Python 3.7+:

pip3 install geolocate

Then, for a single address:

>>> from geolocate import geolocate
>>> geolocate("1 Infinite Loop, Cupertino, CA 95014")
{'latitude': 37.3311841, 'longitude': -122.0287127}

Or, if you want to run things in parallel:

>>> from geolocate import geolocate_batch
>>> geolocate_batch(["1 Infinite Loop, Cupertino, CA 95014", "Eiffel Tower"])
100%|███████| 2/2 [00:01<00:00,  1.66it/s]
[{'latitude': 37.3311841, 'longitude': -122.0287127}, {'latitude': 48.8560934, 'longitude': 2.2930458}]

Advanced usage

Both geolocate and geolocate_batch accept the following keyword arguments:

  • engine (geolocate.engines.GeolocateEngine): Engine to use for geolocating the address. Defaults to geolocate.engines.WazeEngine
  • timeout (int): The timeout in seconds.
  • tries (int): The number of attempts to geolocate the address.
  • backoff_factor (float): The backoff factor. Delay will grow by {backoff factor} * (2 ** ({number of total retries} - 1)).
  • on_not_found (str or callable): A callback function for when the address is not found. The signature of the callback function should be:
    def callback(address: str):
        ...
    
    where address is the address that was not found. The return value of the callback function is returned by the geolocate function.
  • on_error (str or callable): A callback function for when an error occurs. The signature of the callback function should be:
    def callback(address: str, error: Exception):
        ...
    
    where address is the address that caused the error and error is the exception that occurred. The return value of the callback function is returned by the geolocate function.

In addition, the geolocate_batch function accepts the following keyword arguments:

  • num_cpus (int): The number of CPUs to use. If None, the number of CPUs will be determined automatically.

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

geolocate-0.1.2.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geolocate-0.1.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file geolocate-0.1.2.tar.gz.

File metadata

  • Download URL: geolocate-0.1.2.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.2 Linux/5.15.0-1024-azure

File hashes

Hashes for geolocate-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0fab141353380ede2e4b7ab87eb85f54c34ef8854e9360caada7deb9d1bfa187
MD5 c6a3a5f7af8658d37754bb5507f9e329
BLAKE2b-256 ef37a9cf8dafea951dba7261558644b4b7a6c6d071b920fa25ed01ccf774efe5

See more details on using hashes here.

File details

Details for the file geolocate-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: geolocate-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.2 Linux/5.15.0-1024-azure

File hashes

Hashes for geolocate-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5d3417a3711c3aea362d7fb08476ac82e4b8dd2f94e9bc7a0ae246cea0b993b1
MD5 2f6b0a2aad47ce7ff402244c234be3af
BLAKE2b-256 1eb9d8050cd33aec221fdc993b2db4897e33778eba5b59c33a4a26bbf40ed07a

See more details on using hashes here.

Supported by

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