Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MarcoGorelli/polars-reverse-geocode
Fast offline reverse geocoder
https://github.com/MarcoGorelli/polars-reverse-geocode
Last synced: 30 days ago
JSON representation
Fast offline reverse geocoder
- Host: GitHub
- URL: https://github.com/MarcoGorelli/polars-reverse-geocode
- Owner: MarcoGorelli
- License: mit
- Created: 2023-12-20T12:25:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-15T14:24:24.000Z (5 months ago)
- Last Synced: 2024-08-16T15:24:55.299Z (5 months ago)
- Language: Python
- Homepage:
- Size: 193 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-polars - polars-reverse-geocode - This plugin is an offline reverse geocoder for finding the closest city to a given (latitude, longitude) pair by [@MarcoGorelli](https://github.com/MarcoGorelli). (Libraries/Packages/Scripts / Polars plugins)
README
# 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
```python
import polars as plfrom 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 │
└─────────┴───────────┴───────────────────┴────────────┴──────────────┘
```