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 Darwing 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.util 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)
Attempts to decode an invalid Polyline will throw util.EncodingError
Attempts to encode invalid coordinates will throw util.DecodingError
Cython Module 🔥
If you're comfortable with a lack of built-in exceptions, you may 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]]
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.70-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e05527245c37dd5bd96b082850423f879bcb0b3d0525f22f47d3aec7c17184b4 |
|
MD5 | 12780f4efd8314ac65c11095d0a91d75 |
|
BLAKE2b-256 | f493ff80b88884f38342ec81d3fbfc318c563e272b3d17a4ab201e068d328ca2 |
Hashes for pypolyline-0.2.70-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25b9d12f1fa336eead5314ac582b36392ac132fd06f9a62ed4fb26a6b936c3ab |
|
MD5 | ee835924b66d2e006bee42804b332064 |
|
BLAKE2b-256 | f062f968d876aecc6e853e17b1e4d516fbb6a8c08116b6b43a037cf04a148c19 |
Hashes for pypolyline-0.2.70-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed691da2967afa966aaab13eb6a1cfe0704752d87e867e25350cc18ab2e77779 |
|
MD5 | f0bd9f25a8c288c57d4fa9435dac41d3 |
|
BLAKE2b-256 | 786a4d521d5586a682cdf61ced8fb51a5eb0e797085931f8d3e4ae624247dbaa |
Hashes for pypolyline-0.2.70-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f24ad9d9144fb2d7cdb704490033c191975cbe405405d4031fd0d86b62d6ce2 |
|
MD5 | ddbbbec33b3193940a526e2fe5b32d6b |
|
BLAKE2b-256 | 9d13dec01b6cce2f72a38d08b492d5d6c9462e328aa4964cde12bf99787f9813 |
Hashes for pypolyline-0.2.70-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a42fc6b5ecd229d24fed6c3963a410668da1501274e4bf08a6e2d26634bb984 |
|
MD5 | 1bd0265573b18b5145c5a0d009e4d740 |
|
BLAKE2b-256 | 46af6a9f805ec60a30a096c1b92c303fe8cb8a7b0e509374167c88157d1a9fc8 |
Hashes for pypolyline-0.2.70-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71b52c42c16ba6bd01c6569c96c868b37c976e35e7c3e6a8ff36c81ebfd59360 |
|
MD5 | 3cd7e68128d660d811f0909ac6a08fa5 |
|
BLAKE2b-256 | 09bc550ba22b723d26950a8e64b3f565ecb668db26535ffcb73371e935851ecc |
Hashes for pypolyline-0.2.70-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ea0f4b443af40924d0a45e761a751fdd0f8744d43dfef55f05d25146bf7076 |
|
MD5 | 2659fba56ff1c45635d3a462942c6bac |
|
BLAKE2b-256 | 02339b35c6e613a5aa2ad83a32fc052f431997e34b1f8a947cc08dc9aa5b76a3 |
Hashes for pypolyline-0.2.70-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4574ac98a2209602bf6c6e0eae37857fc6917ea6c416610c57496f2f3cdc05dd |
|
MD5 | 93c7f7826e92f78fc46eecad5df35234 |
|
BLAKE2b-256 | a29f5d747d17da00ee2c1210fbbbdcd15e75590c591d77cd4a15fa12cfc25223 |
Hashes for pypolyline-0.2.70-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7dfb6621220e1b125fa4f685a5e3a71aa2a6b83fdf97b7d50c41ae8d2b1eeee |
|
MD5 | 002197fa373f1b0a726358f609d90db6 |
|
BLAKE2b-256 | ba6beccb353500c6a6b0f56f08c95f68019f1bf1aa37f76cbec58033691bda01 |
Hashes for pypolyline-0.2.70-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a0e531a641c334e039474178b277aa925c77cf2fa8c68780a68ead66cbad5a2 |
|
MD5 | 5ba7c9f532cfcaead702433ddf78387f |
|
BLAKE2b-256 | 8380399c74f053f1031666a0457bbabfd3a8475bcecb7d3b98cf2370b4f1a2fc |
Hashes for pypolyline-0.2.70-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fadcacea726f99f4cbaced658c0c0578f7eb7c4923780be6a5710474f6a095e |
|
MD5 | fbc5e3c0165bc679f01b6c74e05d3eb3 |
|
BLAKE2b-256 | e291c87b0bffc19f27adff6b3dada79e20a0769d848f85fe6320e9ab8d384dfa |