Skip to main content

Geocode rows from a SQLite table

Project description

geocode-sqlite

PyPI Changelog Tests License

Geocode rows from a SQLite table

Installation

Install this tool using pip or pipx:

# install inside a virtualenv
pip install geocode-sqlite

# install globally
pipx install geocode-sqlite

Usage

Let's say you have a spreadsheet with addresses in it, and you'd like to map those locations. First, create a SQLite database and insert rows from that spreadsheet using sqlite-utils.

sqlite-utils insert data.db data data.csv --csv

Now, geocode it using OpenStreetMap's Nominatum geocoder.

geocode-sqlite
 --location="{address}, {city}, {state} {zip}" \
 data.db data \
 nominatum  \
 --user-agent="this-is-me"

In the command above, you're using Nominatum, which is free and only asks for a unique user agent.

This will connect to a database (data.db) and read all rows from the table data (skipping any that already have both a latitude and longitude column filled).

You're also telling the geocoder how to extract a location query from a row of data, using Python's built-in string formatting.

For each row where geocoding succeeds, latitude and longitude will be populated. If you hit an error, or a rate limit, run the same query and pick up where you left off.

Note the order of options: There are two sets of options we need to pass.

The first concerns the data we're geocoding. We need to say where our database is and what table we're using, and optionally, how to extract a location query.

Then, we need to say what geocoder we're using, and pass in any options needed to initalize it. This will be different for each geocoder we want to use.

Under the hood, this package uses the excellent geopy library, which is stable and thoroughly road-tested. If you need help understanding a particular geocoder's options, consult geopy's documentation.

Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:

cd geocode-sqlite
python -m venv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

To run the tests:

pytest

Please remember that this library is mainly glue code between other well-tested projects, specifically: click, geopy and sqlite-utils. Tests should focus on making sure those parts fit together correctly. We can assume the parts themselves already work.

To that end, there is a test geocoder included: geocode_sqlite.testing.DummyGeocoder. That geocoder works with an included dataset of In-N-Out Burger locations provided by AllThePlaces. It works like a normal GeoPy geocoder, except it will only return results for In-N-Out locations using the included database.

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

geocode-sqlite-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

geocode_sqlite-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file geocode-sqlite-0.1.0.tar.gz.

File metadata

  • Download URL: geocode-sqlite-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for geocode-sqlite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3613b84f8f360a12df730bb534431870e6317ae08beb5dc68f3619949bf9088
MD5 dc283af1d0257bf6a5936c7b06b18fc7
BLAKE2b-256 de3ad97ee20361736695e55f4936161da09ecd7c46fede73dd581c1b315485ac

See more details on using hashes here.

File details

Details for the file geocode_sqlite-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: geocode_sqlite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for geocode_sqlite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62fccc201d089459f4d77227f08370c7e92a3c577485ed66b11c4008ab3a1a0f
MD5 9524d139427c26cfe9ccb476a766b82a
BLAKE2b-256 242b37d316cc7e4063e1ab75832430fefcdf7a4b1714fa98fb238e3390cd59ba

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