Pypolyline
Fast Google Polyline encoding and decoding using a Rust binary
Install / Use
/learn @urschrei/PypolylineREADME
Fast Google Polyline Encoding and Decoding
Installation
uv add pypolyline
pip install pypolyline
Installing for local development
- Ensure you have a copy of
libpolylineffiandheader.hfrom https://github.com/urschrei/polyline-ffi/releases, and it's in thesrc/pypolylinesubdir - run
uv sync --dev - run
pytest .
Changes in pyx and pxd files, and the Rust library and header will bust the cache, triggering a rebuild when uv commands are run.
Supported Python Versions
All currently supported Python versions.
Supported Platforms
- Linux (
manylinux*-compatible, x86_64 and aarch64) - macOS (x86_64 and arm64)
- Windows 64-bit
Usage
Coordinates must be in (Longitude, Latitude) order
from pypolyline.cutil import encode_coordinates, decode_polyline
coords = [
[52.64125, 23.70162],
[52.64938, 23.70154],
[52.64957, 23.68546],
[52.64122, 23.68549],
[52.64125, 23.70162]
]
# precision is 5 for Google Polyline, 6 for OSRM / Valhalla
polyline = encode_coordinates(coords, 5)
# polyline is 'ynh`IcftoCyq@Ne@ncBds@EEycB'
decoded_coords = decode_polyline(polyline, 5)
Error Handling
Failure to encode coordinates, or to decode a supplied Polyline, will raise a RuntimeError containing information about the invalid input.
How it Works
FFI and a Rust binary
Is It Fast
…Yes.
You can verify this by installing the polyline package, then running benchmarks.py, a calibrated benchmark using cProfile.
On an M2 MBP, The pure-Python test runs in ~2500 ms, the Flexpolyline benchmark runs in ~1500 ms and The Rust + Cython benchmark runs in around 80 ms (30 x and 17.5 x faster, respectively).
License
The Blue Oak Model Licence 1.0.0
Citing Pypolyline
If Pypolyline has been significant in your research, and you would like to acknowledge the project in your academic publication, we suggest citing it as follows (example in APA style, 7th edition):
Hügel, S. (2021). Pypolyline (Version X.Y.Z) [Computer software]. https://doi.org/10.5281/zenodo.5774925
In Bibtex format:
@software{Hugel_Pypolyline_2021,
author = {Hügel, Stephan},
doi = {10.5281/zenodo.5774925},
license = {MIT},
month = {12},
title = {{Pypolyline}},
url = {https://github.com/urschrei/simplification},
version = {X.Y.Z},
year = {2021}
}
Related Skills
himalaya
347.9kCLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
node-connect
347.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
taskflow
347.9kname: taskflow description: Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layer
frontend-design
108.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
