Skip to main content

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"),
)

Release files for polars-reverse-geocode 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars-reverse-geocode 0.8.1
File Size Uploaded
polars_reverse_geocode-0.8.1.tar.gz 33.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-reverse-geocode 0.8.1
File
polars_reverse_geocode-0.8.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
polars_reverse_geocode-0.8.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
polars_reverse_geocode-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 35.9 MB

Release files / polars_reverse_geocode-0.8.1.tar.gz

Download URL polars_reverse_geocode-0.8.1.tar.gz
Size 33.1 kB
Tags Source
SHA-256 checksum
How to use checksums
45956c6268eb0b3e32beb8a3e62e2034bce6711dadc0e18288902ac4c4f8a6f9
BLAKE2b-256 checksum
How to use checksums
fc2ff667ee50c61060c84e4f6d7c7698884b615c416c7cfc0238489491c0d55e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / polars_reverse_geocode-0.8.1-cp39-abi3-win_amd64.whl

Download URL polars_reverse_geocode-0.8.1-cp39-abi3-win_amd64.whl
Size 7.0 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0e64fb6390b1b49c1d39747255adbfa37da213fc41263ed17944a188a90db386
BLAKE2b-256 checksum
How to use checksums
ae8479494ffe6740c696d762083083f3cdc1670a4d7c25e66b469f46c83f6a85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 7.8 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d622567536b678815baf557befc3e7a18368c204d03cf4295f48f687de96acaf
BLAKE2b-256 checksum
How to use checksums
e6371371a9bba9e03fb9ab935079bd67c550e2286663fe2cc06c4d6572318cbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL polars_reverse_geocode-0.8.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 7.2 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
1dde95ee23cfb439a3d95bd7bd816d0c2b82d45017c6204e70505dbb6ff2a1b7
BLAKE2b-256 checksum
How to use checksums
985294cb07d9d8f9666572fab6f85eeab0853aedcc1c1607ed1a43e996672dcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / polars_reverse_geocode-0.8.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL polars_reverse_geocode-0.8.1-cp39-abi3-macosx_11_0_arm64.whl
Size 6.8 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
22becd9fba411a22cd3ef76b4f42a940e051986467deb30fc14eee755d7f87b7
BLAKE2b-256 checksum
How to use checksums
197cc4f7d1bd3541a381b1f0711eac55e64e325db5d7983ce3cf2e9c272ed4df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / polars_reverse_geocode-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL polars_reverse_geocode-0.8.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 7.0 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c4b462716ee73be7d7e281fa67b92d1ded852c00c8cce4248a2aadf4da673d9a
BLAKE2b-256 checksum
How to use checksums
48d7ea9f16df1ceac57f946c0a1bd793eb3744dc905fe2fab0e3093aabe133e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release history Release notifications | RSS feed

This release

0.8.1 This release

6 release files

0.7.8

6 release files

0.7.7

6 release files

0.7.6

6 release files

0.7.3

5 release files

0.7.2

4 release files

0.6.0

5 release files

0.5.0

5 release files

0.4.4

5 release files

0.4.3

5 release files

0.4.2

5 release files

0.4.1

5 release files

0.3.4

5 release files

0.3.3

5 release files

0.1.9

6 release files

0.1.0

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page