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.6
- Python 3.7
- Python 3.8
- Python 3.9 (Linux and macOS 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.5-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbd0020c7076fdec8eec54c7d0a9c198693aa5ee8faefe0460e7c49056497027 |
|
MD5 | 5844be623b7def23b9e999958a0eaeb7 |
|
BLAKE2b-256 | b175e356c15975a8d8b75f28c62a52a54881f6790cbb3e3843f5443ef3fece14 |
Hashes for pypolyline-0.2.5-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 127580e601ac213732340d137e2218f369de45a4e283a4afcbe50548d8eefe4b |
|
MD5 | 4ddc58843a18b48f5e5673d9a3fa3d6d |
|
BLAKE2b-256 | 64ec933f83ad9c835d9c56a5b1a401cb8b7ab81225f718887609a6b544708c6f |
Hashes for pypolyline-0.2.5-cp39-cp39-macosx_10_15_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d1b65d2af31a4f1a4af01aeb130742330fde7b880f67445736cf9a99ba822af |
|
MD5 | 2a350bbc1c7b75bc93013047e2d52717 |
|
BLAKE2b-256 | 702d4780f77c51f3724deb428acfd622b0a21a32ecfd5241e4c48395ad161f0d |
Hashes for pypolyline-0.2.5-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0fe82717429150fbc7742d3faf3ff1f851d25f54da33fb64fbba36db76a885c |
|
MD5 | 6bd34ddef43b40edcaa0c4c6aa7bc4dd |
|
BLAKE2b-256 | 24cafdb03aa7126e5d976b911953bf92a4434af71af5cb14828de4fb34ddb982 |
Hashes for pypolyline-0.2.5-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33f59ddf160e7b174c7547fcedf625c74bd93f055f4b8249b5c767f7ed2e005d |
|
MD5 | ccef719799f3ecc2925f7505b9500caf |
|
BLAKE2b-256 | 6b4ac3983289b2d94afa21c49a012cb6b4c48023221f72f181e8620a5a0ea060 |
Hashes for pypolyline-0.2.5-cp38-cp38-macosx_10_15_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a6b8190149aa35bf4b6d0f76c482598d1554c121b5c8a1b696a93ba663338f |
|
MD5 | b0a6741eec767897ca4113eac8b46456 |
|
BLAKE2b-256 | e4b707e17654600eae193e79cec78b642a2ee1a74c799b2f93c4ba1622c067e8 |
Hashes for pypolyline-0.2.5-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bf454bd06844772f8946056c1e43b8a3ce8846735873a502d510531d7746965 |
|
MD5 | 0e3ed736c1128f02879c43e69ae49762 |
|
BLAKE2b-256 | 80f56875d2efbe5c8b1a9e9b8de452e79b443454a87336aedd4f46bb37b04ab2 |
Hashes for pypolyline-0.2.5-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 862238e150cb994b40baa0418354d32195e8b0a8074aff4eac098bdad02b406e |
|
MD5 | 2ae06028cedbb98d5baca9927267936e |
|
BLAKE2b-256 | 99d57e887eb6ee0bd02131be1cb6005d2c1381979657b265d34a00eb90c35245 |
Hashes for pypolyline-0.2.5-cp37-cp37m-macosx_10_15_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01bd050821341486e4b380393bf7b40813ce0e26a44394bb1eeb77d39a875b36 |
|
MD5 | 87b1969f48acdee88f9b06538693720c |
|
BLAKE2b-256 | 099544a13575ca9f8aaa3f7fb4b3de124f7a7edf719086e20172d93013123db8 |
Hashes for pypolyline-0.2.5-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c915230780a5c03872c975588dbffd9d9ab3c009d09b530d7bfbe9b8b0c1f3df |
|
MD5 | db12c95e7e3eb5c1986b6a18dd7ea107 |
|
BLAKE2b-256 | 009a1cef4b380d2d8826fa0da371d012ebd8a909c1fe6228985e922cc2a933c9 |
Hashes for pypolyline-0.2.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 381e0ca46a9f95de75a801e085a7fb34bcc4a87e71e1356a42440d286d54928b |
|
MD5 | 3fefce99aa179f585b2a9ee9b2a249f2 |
|
BLAKE2b-256 | cfc44eb881f64b9dabd9a94fe0d87f502d5114d9c5bca1e4249575f4c79538e1 |
Hashes for pypolyline-0.2.5-cp36-cp36m-macosx_10_15_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d71fce48453edb1f168dff9045094f438360af45827ee242e6c2678fd4aee6e5 |
|
MD5 | e671ec5295dabaa5840894c10ba8811f |
|
BLAKE2b-256 | 89c5c0161da3448412c867260e1faf4bb0b3b60f4c4f2f9efb2d9ab833c9a0a9 |