Fast Google Polyline encoding and decoding using Rust FFI
Project description
Fast Google Polyline Encoding and Decoding
Installation
pip install pypolyline
Please use a recent (>= 8.1.2) version of pip
.
Supported Python Versions
- Python 3.7
- Python 3.8 (Linux and macOS Darwin only)
- Python 3.9 (Linux and macOS Darwin only)
- Python 3.10 (Linux and macOS Darwin only)
Supported Platforms
- Linux (
manylinux1
-compatible) - OS X
- Windows 32-bit / 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)
Cython Module 🔥
If you're comfortable with a lack of built-in exceptions, you should use the compiled Cython version of the functions, giving a 3x speedup over the ctypes
functions:
from pypolyline.cutil import encode_coordinates, decode_polyline
- Longitude errors will return strings beginning with
Longitude error:
- Latitude errors will return strings beginning with
Latitude error:
- Polyline errors will return
[[nan, nan]]
Otherwise, import from util
instead, for a slower, ctypes
-based interface. Attempts to decode an invalid Polyline will throw util.EncodingError
Attempts to encode invalid coordinates will throw util.DecodingError
How it Works
FFI and a Rust binary
Is It Fast
…Yes.
You can verify this by installing the polyline
and cgpolyencode
packages, then running benchmarks.py
, a calibrated benchmark using cProfile
.
On a 1.8 GHz Intel Core i7, The pure-Python test runs in ~21 s, the C++ (cgpolyencode.GPolyEncoder
) test runs in around 600 ms, and The Rust + Cython benchmark runs in around 400 ms (33% faster).
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for pypolyline-0.2.71-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c42a06e4f2b7361122da1f0bdfd2fde73dc97b5de8988288f98d62dbb24a447f |
|
MD5 | ab4c86a24d969bee9a2412eded00898c |
|
BLAKE2b-256 | 9afc6c68be6b6522794f0bec6ec5edbf55fc7c755c5b060cc1e8e6c578d88a17 |
Hashes for pypolyline-0.2.71-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee133584e37a83d1a17c330d7290158bad867f7328cd34a4f615ec51c32c6b2f |
|
MD5 | e35c32acc03501021b4a59a97d886e44 |
|
BLAKE2b-256 | 3cc01be83736264d174f75e2c6cc9e3d58c63ca22370d5b815957468563737ef |
Hashes for pypolyline-0.2.71-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bf7cc6fb11b4b9bc56f6c3d956b65b665f0b147b1269606276c97ecf5da7853 |
|
MD5 | 7cfb8205020f0eea8cb66d6e971204de |
|
BLAKE2b-256 | 84cbc3e2f2045cb554c7118bc1ff185dc9f5f55b4d4f1182811ad4ab95038aa7 |
Hashes for pypolyline-0.2.71-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d2a1196d0d51fd88c50cb202f3bff017164afefe3cd2556eaeab76d00f71ef9 |
|
MD5 | c8aebce2f8adafe347b2ca715291073a |
|
BLAKE2b-256 | 3ef3405c0486cbe20e5615f5725bb7c0e24ba2edfffd885891f74926a9208efc |
Hashes for pypolyline-0.2.71-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74449e4a36fad04f3161e9c7b03c1a140bedd7dbb474e59e7a8d6eb592ec6f53 |
|
MD5 | cf2cb9accdd79a94d7e76fba7c6c74a6 |
|
BLAKE2b-256 | fc7f798f0a1a4118a442fdf146016b9c502c0086d3118e8f34864f7c10653461 |
Hashes for pypolyline-0.2.71-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58f85c296f52606501ef6e06112032785fc66af7d43396330e299423504796ae |
|
MD5 | cd9a5db48be26ec92949ece651a9da54 |
|
BLAKE2b-256 | 558426149b019ce8cf71c74d44f05e4cc2bcfdf61e84577ea2cdf1a686afe3f8 |
Hashes for pypolyline-0.2.71-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5be66577228b570ca76dc3f77a7938261d1193ec68de48092d15fa44d3d485e6 |
|
MD5 | b80e40edac58b888c7808fc314c82a62 |
|
BLAKE2b-256 | 054cad2aeea8dfc2cbaf67df51181dae3c590b6f076739b656dd821045696172 |
Hashes for pypolyline-0.2.71-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0ac6d50ef0b4d67121f060e1326177325a9571cf8a986cdfc8fa4234390922d |
|
MD5 | 8e246b80c0be7bf444ca56879c833de1 |
|
BLAKE2b-256 | 4c9a8e872ca1b133057581df155c763e3e2db5d851795d69e321234cb665f268 |
Hashes for pypolyline-0.2.71-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7c791a3e6747a22e8f158db3f2affabe7da1e0ac8bdc01a15ac9caef79ecf09 |
|
MD5 | 2cffd983603bdcdf56aa13846625754e |
|
BLAKE2b-256 | e238a53e2286da06156e477f6edb4c3f70fc2de397fab39a40dc9426a89b7242 |
Hashes for pypolyline-0.2.71-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2731261031e53f96489a8b22e473df9d396b56e15de2b1d96b6fd8f37e9aee8d |
|
MD5 | 759b7c228cf43fcfdeccc00b71c496a3 |
|
BLAKE2b-256 | b7f6f6155fb0bcecbbdd67b42fc94f55186bafc31c6591cc27e80043a6762c23 |
Hashes for pypolyline-0.2.71-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eab8baed5736fb64c62a14208c519c853db8cc6be1b3bc679d77203299a715b8 |
|
MD5 | ee5016e17e24c0fab7f7dfcec83b59a5 |
|
BLAKE2b-256 | 26146e965730cc0a4da9303b472f4c654cbcdab7de2101b8a069190f0ac95be4 |