Polars-Reverse-Geocode
Polars plugin based on https://github.com/gx0r/rrgeo.
rrgeo takes a latitude and longitude as input and returns the closest city, country, latitude, and longitude, using a k-d tree to efficiently find the nearest neighbour based on a known list of locations. This can be useful if you need to reverse geocode a large number of coordinates quickly, or just need the rough location of coordinates but don't want the expense or complication of an online reverse geocoder.
Installation
pip install polars-reverse-geocode
Usage example
import polars as pl
from polars_reverse_geocode import find_closest_city, find_closest_state, find_closest_country
df = pl.DataFrame({
'lat': [37.7749, 51.01, 52.5],
'lon': [-122.4194, -3.9, -.91]
})
print(
df.with_columns(
city = find_closest_city('lat', 'lon'),
state = find_closest_state('lat', 'lon'),
country_code = find_closest_country('lat', 'lon')
)
)
shape: (3, 5)
┌─────────┬───────────┬───────────────────┬────────────┬──────────────┐
│ lat ┆ lon ┆ city ┆ state ┆ country_code │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ str ┆ str ┆ str │
╞═════════╪═══════════╪═══════════════════╪════════════╪══════════════╡
│ 37.7749 ┆ -122.4194 ┆ San Francisco ┆ California ┆ US │
│ 51.01 ┆ -3.9 ┆ South Molton ┆ England ┆ GB │
│ 52.5 ┆ -0.91 ┆ Market Harborough ┆ England ┆ GB │
└─────────┴───────────┴───────────────────┴────────────┴──────────────┘
Caching
Loading the geocoding data set has a fixed cost of roughly 150ms, which is
noticeable when doing repeated, one-off lookups (e.g. sequential/chained
calls in a UI). Each find_closest_* function accepts a cache_mode
keyword argument to control this caching behaviour:
"cache_forever"(default): loads the data set once per process and keeps it in memory (~2.5GB RAM) for the lifetime of the process, so subsequent calls are fast."do_not_cache": does not populate the shared, process-wide cache. If the cache has already been populated (e.g. by an earlier"cache_forever"call), it's reused; otherwise, the data set is loaded fresh on every call, and discarded afterwards, avoiding the memory cost.
df.with_columns(
city=find_closest_city("lat", "lon", cache_mode="do_not_cache"),
)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_reverse_geocode-0.8.1.tar.gz.
File metadata
- Download URL: polars_reverse_geocode-0.8.1.tar.gz
- Upload date:
- Size: 33.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45956c6268eb0b3e32beb8a3e62e2034bce6711dadc0e18288902ac4c4f8a6f9
|
|
| MD5 |
4706d0a83b436bbde74195c1d777d5fe
|
|
| BLAKE2b-256 |
fc2ff667ee50c61060c84e4f6d7c7698884b615c416c7cfc0238489491c0d55e
|
File details
Details for the file polars_reverse_geocode-0.8.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: polars_reverse_geocode-0.8.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e64fb6390b1b49c1d39747255adbfa37da213fc41263ed17944a188a90db386
|
|
| MD5 |
cf81f333bd4ef4434891418dde10e34f
|
|
| BLAKE2b-256 |
ae8479494ffe6740c696d762083083f3cdc1670a4d7c25e66b469f46c83f6a85
|
File details
Details for the file polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.8 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d622567536b678815baf557befc3e7a18368c204d03cf4295f48f687de96acaf
|
|
| MD5 |
dd21c022f50623d38df0b8ad1e2a2167
|
|
| BLAKE2b-256 |
e6371371a9bba9e03fb9ab935079bd67c550e2286663fe2cc06c4d6572318cbe
|
File details
Details for the file polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 7.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dde95ee23cfb439a3d95bd7bd816d0c2b82d45017c6204e70505dbb6ff2a1b7
|
|
| MD5 |
e1f75bf4dbcaba2cc33166f2f80b5655
|
|
| BLAKE2b-256 |
985294cb07d9d8f9666572fab6f85eeab0853aedcc1c1607ed1a43e996672dcc
|
File details
Details for the file polars_reverse_geocode-0.8.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_reverse_geocode-0.8.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 6.8 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22becd9fba411a22cd3ef76b4f42a940e051986467deb30fc14eee755d7f87b7
|
|
| MD5 |
bd3d2f600a418a5a7aa6f26264c842cb
|
|
| BLAKE2b-256 |
197cc4f7d1bd3541a381b1f0711eac55e64e325db5d7983ce3cf2e9c272ed4df
|
File details
Details for the file polars_reverse_geocode-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: polars_reverse_geocode-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b462716ee73be7d7e281fa67b92d1ded852c00c8cce4248a2aadf4da673d9a
|
|
| MD5 |
9ac13cd4c44a40e3dad70f06854cd331
|
|
| BLAKE2b-256 |
48d7ea9f16df1ceac57f946c0a1bd793eb3744dc905fe2fab0e3093aabe133e4
|