larzgeo
Geospatial basics in pure Python. Zero dependencies.
The handful of geo operations most apps actually need - distance, bearing, geohashing, bounding boxes, and point-in-polygon - without GDAL, shapely, or any dependency.
from larzgeo import haversine, geohash_encode, point_in_polygon
haversine(51.5074, -0.1278, 48.8566, 2.3522) # London->Paris ~343 km
geohash_encode(57.64911, 10.40744, 11) # 'u4pruydqqvj'
point_in_polygon((2, 2), [(0, 0), (0, 4), (4, 4), (4, 0)]) # True
Why
- Just the essentials, correct. Great-circle (haversine) distance in km/mi/m/
nautical-mi, initial bearing,
destination(project a point),midpoint,bounding_box(to pre-filter a radius query cheaply), geohash encode/decode (tested against the canonicalu4pruydqqvjvector), and ray-casting point-in-polygon that handles concave shapes. - No heavyweight geo stack. GDAL/shapely are powerful and huge; for "how far is X from Y", "is this point in this area", and "give me a geohash", this installs anywhere in seconds.
- Zero dependencies.
Install
pip install larzgeo
Usage
from larzgeo import (haversine, bearing, destination, midpoint,
bounding_box, geohash_encode, geohash_decode, point_in_polygon)
haversine(lat1, lon1, lat2, lon2, unit="km") # or "mi" / "m" / "nmi"
bearing(lat1, lon1, lat2, lon2) # degrees, 0=N 90=E
destination(lat, lon, bearing_deg, distance) # -> (lat, lon)
bounding_box(lat, lon, radius_km) # (min_lat, min_lon, max_lat, max_lon)
geohash_encode(lat, lon, precision=12)
geohash_decode(hash) # -> (lat, lon)
point_in_polygon((x, y), [(x1, y1), ...]) # ray casting
Tests
python -m unittest discover -s tests -v # 17 tests incl. geohash vector + concave polygons
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.
License
MIT (c) larz-scripter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
larzgeo-0.1.0.tar.gz
(5.8 kB
view details)
Built Distribution
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 larzgeo-0.1.0.tar.gz.
File metadata
- Download URL: larzgeo-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29ad955a13061497374a3a7bec48326dd1f9558e597d93accd2bcfc314d94f64
|
|
| MD5 |
780a31254352bd19839bdbfd31f0c00a
|
|
| BLAKE2b-256 |
87a6fb38c6913e7193b687ac56620e1f2c39cf5c88eaff74a96448795874e01e
|
File details
Details for the file larzgeo-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzgeo-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5430bd183a4f40e32c1530b416260824995d429e65a021ef89087ba6f780eae7
|
|
| MD5 |
ae1f8f384b75a1396856ecd2204b782a
|
|
| BLAKE2b-256 |
823eb89a283be21b05b13fcc68cf4a5f2c01d0bdfb308a6ad31390de569c22a7
|