home / content / repos

repos: 293361514

This data as json

id node_id name full_name private owner html_url description fork created_at updated_at pushed_at homepage size stargazers_count watchers_count language has_issues has_projects has_downloads has_wiki has_pages forks_count archived disabled open_issues_count license topics forks open_issues watchers default_branch permissions temp_clone_token organization network_count subscribers_count readme readme_html allow_forking visibility is_template template_repository web_commit_signoff_required has_discussions
293361514 MDEwOlJlcG9zaXRvcnkyOTMzNjE1MTQ= geocode-sqlite eyeseast/geocode-sqlite 0 25778 https://github.com/eyeseast/geocode-sqlite Geocode rows in a SQLite database table 0 2020-09-06T21:05:39Z 2022-11-02T19:19:56Z 2022-11-07T17:31:05Z   125 223 223 Python 1 1 1 1 0 6 0 0 8 apache-2.0 [] 6 8 223 main {"admin": false, "maintain": false, "push": false, "triage": false, "pull": false}     6 5 # geocode-sqlite [![PyPI](https://img.shields.io/pypi/v/geocode-sqlite.svg)](https://pypi.org/project/geocode-sqlite/) [![Changelog](https://img.shields.io/github/v/release/eyeseast/geocode-sqlite?include_prereleases&label=changelog)](https://github.com/eyeseast/geocode-sqlite/releases) [![Tests](https://github.com/eyeseast/geocode-sqlite/workflows/Test/badge.svg)](https://github.com/eyeseast/geocode-sqlite/actions?query=workflow%3ATest) [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/eyeseast/geocode-sqlite/blob/master/LICENSE) Geocode rows from a SQLite table ## Installation Install this tool using `pip` or `pipx`: ```sh # 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`. ```sh sqlite-utils insert data.db data data.csv --csv ``` Now, geocode it using OpenStreetMap's Nominatim geocoder. ```sh geocode-sqlite nominatim data.db data \ --location="{address}, {city}, {state} {zip}" \ --delay=1 \ --user-agent="this-is-me" ``` In the command above, you're using Nominatim, which is free and only asks for a unique user agent (`--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 (`--location`) from a row of data, using Python's built-in string formatting, and setting a rate limit (`--delay`) of one request per second. 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. The resulting table layout can be visualized with [datasette-cluster-map](https://datasette.io/plugins/datasette-cluster-map). Under the hood, this package uses the excellent [geopy](https://geopy.readthedocs.io/en/latest/) library, which is stable and thoroughly road-tested. If you need help understanding a particular geocoder's options, consult [geopy's documentation](https://geopy.readthedocs.io/en/latest/#module-geopy.geocoders). ### Supported Geocoders The CLI currently supports these geocoders: - `bing` - `googlev3` - `mapquest` (and `open-mapquest`) - `mapbox` - `nominatim` - `opencage` #### Adding new geocoders 1. Open an issue with the name of the geocoding service as the ticket title ([example](https://github.com/eyeseast/geocode-sqlite/issues/35)). Put any noteworthy implementation details in the ticket body, like where to get an API key if one is required. 2. Fork the repo and add a geocoder. 3. Add an example to the `Makefile`. Add tests if there's new shared functionality. ### Common arguments and options Each geocoder needs to know where to find the data it's working with. These are the first two arguments: - `database`: a path to a SQLite file, which must already exist - `table`: the name of a table, in that database, which exists and has data to geocode From there, we have a set of options passed to every geocoder: - `location`: a [string format](https://docs.python.org/3/library/stdtypes.html#str.format) that will be expanded with each row to build a full query, to be geocoded - `delay`: a delay between each call (some services require this) - `latitude`: latitude column name - `longitude`: longitude column name - `geojson`: store results as GeoJSON, instead of in latitude and longitude columns - `spatialite`: store results in a SpatiaLite geometry column, instead of in latitude and longitude columns - `raw`: store raw geocoding results in a JSON column Each geocoder takes additional, specific arguments beyond these, such as API keys. Again, [geopy's documentation](https://geopy.readthedocs.io/en/latest/#module-geopy.geocoders) is an excellent resource. ## Using SpatiaLite The `--spatialite` flag will store results in a [geometry column](https://www.gaia-gis.it/gaia-sins/spatialite-cookbook-5/cookbook_topics.adminstration.html#topic_TABLE_to_SpatialTable), instead of `latitude` and `longitude` columns. This is useful if you're doing other GIS operations, such as using a [spatial index](https://www.gaia-gis.it/fossil/libspatialite/wiki?name=SpatialIndex). See the [SpatiaLite cookbook](https://www.gaia-gis.it/gaia-sins/spatialite-cookbook-5/index.html) and [functions list](https://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html) for more of what's possible. ## Capturing additional geocoding data Geocoding services typically return more data than just coordinates. This might include accuracy, normalized addresses or other context. This can be captured using the `--raw` flag. By default, this will add a `raw` column and store the full geocoding response as JSON. If you want to rename that column, pass a value, like `--raw custom_raw`. The shape of this response object will vary between services. You can query specific values using [SQLite's built-in JSON functions](https://www.sqlite.org/json1.html). For example, this will work with Google's geocoder: ```sql select json_extract(raw, '$.formatted_address') as address, json_extract(raw, '$.geometry.location_type') as location_type from innout_test ``` Check each geocoding service's documentation for what's included in the response. ## Python API The command line interface aims to support the most common options for each geocoder. For more fine-grained control, use the Python API. As with the CLI, this assumes you already have a SQLite database and a table of location data. ```python from geocode_sqlite import geocode_table from geopy.geocoders import Nominatim # create a geocoder instance, with some extra options nominatim = Nominatim(user_agent="this-is-me", domain="nominatim.local.dev", scheme="http") # assuming our database is in the same directory count = geocode_table("data.db", "data", query_template="{address}, {city}, {state} {zip}") # when it's done print(f"Geocoded {count} rows") ``` Any [geopy geocoder](https://geopy.readthedocs.io/en/latest/#module-geopy.geocoders) can be used with the Python API. ## Development To contribute to this tool, first checkout the code. Then create a new virtual environment: ```sh cd geocode-sqlite python -m venv .venv source .venv/bin/activate ``` Or if you are using `pipenv`: ```sh pipenv shell ``` Now install the dependencies and tests: ```sh pip install -e '.[test]' ``` To run the tests: ```sh pytest ``` Please remember that this library is mainly glue code between other well-tested projects, specifically: [click](https://click.palletsprojects.com/), [geopy](https://geopy.readthedocs.io/en/stable/) and [sqlite-utils](https://sqlite-utils.datasette.io/en/stable/). 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](https://www.alltheplaces.xyz/). It works like a normal GeoPy geocoder, except it will only return results for In-N-Out locations using the included database. <div id="readme" class="md" data-path="README.md"><article class="markdown-body entry-content container-lg" itemprop="text"><h1 dir="auto"><a id="user-content-geocode-sqlite" class="anchor" aria-hidden="true" href="#user-content-geocode-sqlite"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>geocode-sqlite</h1> <p dir="auto"><a href="https://pypi.org/project/geocode-sqlite/" rel="nofollow"><img src="https://camo.githubusercontent.com/48afed6b156b122a781142db699a225016ec438b4f64f9534d5f852433332a50/68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f67656f636f64652d73716c6974652e737667" alt="PyPI" data-canonical-src="https://img.shields.io/pypi/v/geocode-sqlite.svg" style="max-width: 100%;"></a> <a href="https://github.com/eyeseast/geocode-sqlite/releases"><img src="https://camo.githubusercontent.com/cca0e9a2e0f5dbbfb761aeb9803bac6602b9831541a309b6c5a73ebec690b35e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f65796573656173742f67656f636f64652d73716c6974653f696e636c7564655f70726572656c6561736573266c6162656c3d6368616e67656c6f67" alt="Changelog" data-canonical-src="https://img.shields.io/github/v/release/eyeseast/geocode-sqlite?include_prereleases&amp;label=changelog" style="max-width: 100%;"></a> <a href="https://github.com/eyeseast/geocode-sqlite/actions?query=workflow%3ATest"><img src="https://github.com/eyeseast/geocode-sqlite/workflows/Test/badge.svg" alt="Tests" style="max-width: 100%;"></a> <a href="https://github.com/eyeseast/geocode-sqlite/blob/master/LICENSE"><img src="https://camo.githubusercontent.com/1698104e976c681143eb0841f9675c6f802bb7aa832afc0c7a4e719b1f3cf955/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e737667" alt="License" data-canonical-src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" style="max-width: 100%;"></a></p> <p dir="auto">Geocode rows from a SQLite table</p> <h2 dir="auto"><a id="user-content-installation" class="anchor" aria-hidden="true" href="#user-content-installation"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Installation</h2> <p dir="auto">Install this tool using <code>pip</code> or <code>pipx</code>:</p> <div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# install inside a virtualenv pip install geocode-sqlite # install globally pipx install geocode-sqlite"><pre><span class="pl-c"><span class="pl-c">#</span> install inside a virtualenv</span> pip install geocode-sqlite <span class="pl-c"><span class="pl-c">#</span> install globally</span> pipx install geocode-sqlite</pre></div> <h2 dir="auto"><a id="user-content-usage" class="anchor" aria-hidden="true" href="#user-content-usage"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Usage</h2> <p dir="auto">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 <code>sqlite-utils</code>.</p> <div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="sqlite-utils insert data.db data data.csv --csv"><pre>sqlite-utils insert data.db data data.csv --csv</pre></div> <p dir="auto">Now, geocode it using OpenStreetMap's Nominatim geocoder.</p> <div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="geocode-sqlite nominatim data.db data \ --location=&quot;{address}, {city}, {state} {zip}&quot; \ --delay=1 \ --user-agent=&quot;this-is-me&quot;"><pre>geocode-sqlite nominatim data.db data \ --location=<span class="pl-s"><span class="pl-pds">"</span>{address}, {city}, {state} {zip}<span class="pl-pds">"</span></span> \ --delay=1 \ --user-agent=<span class="pl-s"><span class="pl-pds">"</span>this-is-me<span class="pl-pds">"</span></span></pre></div> <p dir="auto">In the command above, you're using Nominatim, which is free and only asks for a unique user agent (<code>--user-agent</code>).</p> <p dir="auto">This will connect to a database (<code>data.db</code>) and read all rows from the table <code>data</code> (skipping any that already have both a <code>latitude</code> and <code>longitude</code> column filled).</p> <p dir="auto">You're also telling the geocoder how to extract a location query (<code>--location</code>) from a row of data, using Python's built-in string formatting, and setting a rate limit (<code>--delay</code>) of one request per second.</p> <p dir="auto">For each row where geocoding succeeds, <code>latitude</code> and <code>longitude</code> will be populated. If you hit an error, or a rate limit, run the same query and pick up where you left off.</p> <p dir="auto">The resulting table layout can be visualized with <a href="https://datasette.io/plugins/datasette-cluster-map" rel="nofollow">datasette-cluster-map</a>.</p> <p dir="auto">Under the hood, this package uses the excellent <a href="https://geopy.readthedocs.io/en/latest/" rel="nofollow">geopy</a> library, which is stable and thoroughly road-tested. If you need help understanding a particular geocoder's options, consult <a href="https://geopy.readthedocs.io/en/latest/#module-geopy.geocoders" rel="nofollow">geopy's documentation</a>.</p> <h3 dir="auto"><a id="user-content-supported-geocoders" class="anchor" aria-hidden="true" href="#user-content-supported-geocoders"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Supported Geocoders</h3> <p dir="auto">The CLI currently supports these geocoders:</p> <ul dir="auto"> <li><code>bing</code></li> <li><code>googlev3</code></li> <li><code>mapquest</code> (and <code>open-mapquest</code>)</li> <li><code>mapbox</code></li> <li><code>nominatim</code></li> <li><code>opencage</code></li> </ul> <h4 dir="auto"><a id="user-content-adding-new-geocoders" class="anchor" aria-hidden="true" href="#user-content-adding-new-geocoders"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Adding new geocoders</h4> <ol dir="auto"> <li>Open an issue with the name of the geocoding service as the ticket title (<a href="https://github.com/eyeseast/geocode-sqlite/issues/35" data-hovercard-type="issue" data-hovercard-url="/eyeseast/geocode-sqlite/issues/35/hovercard">example</a>). Put any noteworthy implementation details in the ticket body, like where to get an API key if one is required.</li> <li>Fork the repo and add a geocoder.</li> <li>Add an example to the <code>Makefile</code>. Add tests if there's new shared functionality.</li> </ol> <h3 dir="auto"><a id="user-content-common-arguments-and-options" class="anchor" aria-hidden="true" href="#user-content-common-arguments-and-options"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Common arguments and options</h3> <p dir="auto">Each geocoder needs to know where to find the data it's working with. These are the first two arguments:</p> <ul dir="auto"> <li><code>database</code>: a path to a SQLite file, which must already exist</li> <li><code>table</code>: the name of a table, in that database, which exists and has data to geocode</li> </ul> <p dir="auto">From there, we have a set of options passed to every geocoder:</p> <ul dir="auto"> <li><code>location</code>: a <a href="https://docs.python.org/3/library/stdtypes.html#str.format" rel="nofollow">string format</a> that will be expanded with each row to build a full query, to be geocoded</li> <li><code>delay</code>: a delay between each call (some services require this)</li> <li><code>latitude</code>: latitude column name</li> <li><code>longitude</code>: longitude column name</li> <li><code>geojson</code>: store results as GeoJSON, instead of in latitude and longitude columns</li> <li><code>spatialite</code>: store results in a SpatiaLite geometry column, instead of in latitude and longitude columns</li> <li><code>raw</code>: store raw geocoding results in a JSON column</li> </ul> <p dir="auto">Each geocoder takes additional, specific arguments beyond these, such as API keys. Again, <a href="https://geopy.readthedocs.io/en/latest/#module-geopy.geocoders" rel="nofollow">geopy's documentation</a> is an excellent resource.</p> <h2 dir="auto"><a id="user-content-using-spatialite" class="anchor" aria-hidden="true" href="#user-content-using-spatialite"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Using SpatiaLite</h2> <p dir="auto">The <code>--spatialite</code> flag will store results in a <a href="https://www.gaia-gis.it/gaia-sins/spatialite-cookbook-5/cookbook_topics.adminstration.html#topic_TABLE_to_SpatialTable" rel="nofollow">geometry column</a>, instead of <code>latitude</code> and <code>longitude</code> columns. This is useful if you're doing other GIS operations, such as using a <a href="https://www.gaia-gis.it/fossil/libspatialite/wiki?name=SpatialIndex" rel="nofollow">spatial index</a>. See the <a href="https://www.gaia-gis.it/gaia-sins/spatialite-cookbook-5/index.html" rel="nofollow">SpatiaLite cookbook</a> and <a href="https://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html" rel="nofollow">functions list</a> for more of what's possible.</p> <h2 dir="auto"><a id="user-content-capturing-additional-geocoding-data" class="anchor" aria-hidden="true" href="#user-content-capturing-additional-geocoding-data"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Capturing additional geocoding data</h2> <p dir="auto">Geocoding services typically return more data than just coordinates. This might include accuracy, normalized addresses or other context. This can be captured using the <code>--raw</code> flag. By default, this will add a <code>raw</code> column and store the full geocoding response as JSON. If you want to rename that column, pass a value, like <code>--raw custom_raw</code>.</p> <p dir="auto">The shape of this response object will vary between services. You can query specific values using <a href="https://www.sqlite.org/json1.html" rel="nofollow">SQLite's built-in JSON functions</a>. For example, this will work with Google's geocoder:</p> <div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="select json_extract(raw, '$.formatted_address') as address, json_extract(raw, '$.geometry.location_type') as location_type from innout_test"><pre><span class="pl-k">select</span> json_extract(raw, <span class="pl-s"><span class="pl-pds">'</span>$.formatted_address<span class="pl-pds">'</span></span>) <span class="pl-k">as</span> address, json_extract(raw, <span class="pl-s"><span class="pl-pds">'</span>$.geometry.location_type<span class="pl-pds">'</span></span>) <span class="pl-k">as</span> location_type <span class="pl-k">from</span> innout_test</pre></div> <p dir="auto">Check each geocoding service's documentation for what's included in the response.</p> <h2 dir="auto"><a id="user-content-python-api" class="anchor" aria-hidden="true" href="#user-content-python-api"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Python API</h2> <p dir="auto">The command line interface aims to support the most common options for each geocoder. For more fine-grained control, use the Python API.</p> <p dir="auto">As with the CLI, this assumes you already have a SQLite database and a table of location data.</p> <div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from geocode_sqlite import geocode_table from geopy.geocoders import Nominatim # create a geocoder instance, with some extra options nominatim = Nominatim(user_agent=&quot;this-is-me&quot;, domain=&quot;nominatim.local.dev&quot;, scheme=&quot;http&quot;) # assuming our database is in the same directory count = geocode_table(&quot;data.db&quot;, &quot;data&quot;, query_template=&quot;{address}, {city}, {state} {zip}&quot;) # when it's done print(f&quot;Geocoded {count} rows&quot;)"><pre><span class="pl-k">from</span> <span class="pl-s1">geocode_sqlite</span> <span class="pl-k">import</span> <span class="pl-s1">geocode_table</span> <span class="pl-k">from</span> <span class="pl-s1">geopy</span>.<span class="pl-s1">geocoders</span> <span class="pl-k">import</span> <span class="pl-v">Nominatim</span> <span class="pl-c"># create a geocoder instance, with some extra options</span> <span class="pl-s1">nominatim</span> <span class="pl-c1">=</span> <span class="pl-v">Nominatim</span>(<span class="pl-s1">user_agent</span><span class="pl-c1">=</span><span class="pl-s">"this-is-me"</span>, <span class="pl-s1">domain</span><span class="pl-c1">=</span><span class="pl-s">"nominatim.local.dev"</span>, <span class="pl-s1">scheme</span><span class="pl-c1">=</span><span class="pl-s">"http"</span>) <span class="pl-c"># assuming our database is in the same directory</span> <span class="pl-s1">count</span> <span class="pl-c1">=</span> <span class="pl-en">geocode_table</span>(<span class="pl-s">"data.db"</span>, <span class="pl-s">"data"</span>, <span class="pl-s1">query_template</span><span class="pl-c1">=</span><span class="pl-s">"{address}, {city}, {state} {zip}"</span>) <span class="pl-c"># when it's done</span> <span class="pl-en">print</span>(<span class="pl-s">f"Geocoded <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">count</span><span class="pl-kos">}</span></span> rows"</span>)</pre></div> <p dir="auto">Any <a href="https://geopy.readthedocs.io/en/latest/#module-geopy.geocoders" rel="nofollow">geopy geocoder</a> can be used with the Python API.</p> <h2 dir="auto"><a id="user-content-development" class="anchor" aria-hidden="true" href="#user-content-development"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Development</h2> <p dir="auto">To contribute to this tool, first checkout the code. Then create a new virtual environment:</p> <div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="cd geocode-sqlite python -m venv .venv source .venv/bin/activate"><pre><span class="pl-c1">cd</span> geocode-sqlite python -m venv .venv <span class="pl-c1">source</span> .venv/bin/activate</pre></div> <p dir="auto">Or if you are using <code>pipenv</code>:</p> <div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pipenv shell"><pre>pipenv shell</pre></div> <p dir="auto">Now install the dependencies and tests:</p> <div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pip install -e '.[test]'"><pre>pip install -e <span class="pl-s"><span class="pl-pds">'</span>.[test]<span class="pl-pds">'</span></span></pre></div> <p dir="auto">To run the tests:</p> <div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pytest"><pre>pytest</pre></div> <p dir="auto">Please remember that this library is mainly glue code between other well-tested projects, specifically: <a href="https://click.palletsprojects.com/" rel="nofollow">click</a>, <a href="https://geopy.readthedocs.io/en/stable/" rel="nofollow">geopy</a> and <a href="https://sqlite-utils.datasette.io/en/stable/" rel="nofollow">sqlite-utils</a>. Tests should focus on making sure those parts fit together correctly. We can assume the parts themselves already work.</p> <p dir="auto">To that end, there is a test geocoder included: <code>geocode_sqlite.testing.DummyGeocoder</code>. That geocoder works with an included dataset of In-N-Out Burger locations provided by <a href="https://www.alltheplaces.xyz/" rel="nofollow">AllThePlaces</a>. It works like a normal GeoPy geocoder, except it will only return results for In-N-Out locations using the included database.</p> </article></div> 1 public 0   0 0

Links from other tables

  • 14 rows from repo in releases
Powered by Datasette · Queries took 5.462ms