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 2.7
- Python 3.6
- Python 3.7
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.4-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96e15bcc1d241785470329fed2a038be46d259689c132ffd4f1b4887400757cc |
|
MD5 | 1b58ab6ec3330355b470395a9dd99ede |
|
BLAKE2b-256 | e5752279d97c53c2bd7d87aef2f4d170611ad6b3359bb6e558bc0de0b9e522b3 |
Hashes for pypolyline-0.2.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6a8e27332eb831e3c6d4ef130a465563a5e7f9fd7f2fcd761efafbe2692f42 |
|
MD5 | 3df6bd2a2c4b286121e126047eb89664 |
|
BLAKE2b-256 | ade4e5329aff8920ae29835024ef2fae8828bb8a03d891d438ff7149ef653c6f |
Hashes for pypolyline-0.2.4-cp38-cp38-macosx_10_13_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 | 02f3320aa98070f73940a4d0ee258b21d4596acc373a2e905891d9f3d3874c1f |
|
MD5 | 1c00bca7337af11039fc966510fd3a77 |
|
BLAKE2b-256 | 09b35e257ca08dc11ad97be61cc6861308cc6af88b6e760636d6f484a0c40b93 |
Hashes for pypolyline-0.2.4-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a74c6d7fcde2674bfc0c68b6ff966581ae1c09af3ac1833f927b21736fcc43 |
|
MD5 | ce23ff88be94bb78b375c28c5e9b7171 |
|
BLAKE2b-256 | 6989d39650b43befec2b3c5fe2a1e6c77525cfb89e6265be0e15e54607a47a18 |
Hashes for pypolyline-0.2.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b39485679002440cc177702436b46f86e0bdf7c8afe170c776649e2d3461fb5 |
|
MD5 | 3728e937a70241e5f352218da48b5526 |
|
BLAKE2b-256 | dd8b2ec574c297cadeb8685d1bc32ebd2aa1c150f4a9877225f68b2db6ed7b45 |
Hashes for pypolyline-0.2.4-cp37-cp37m-macosx_10_13_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 | 4a4b9b2bd7ed55f98cd8394ac20cfda32c4e250d617cde93fa74e408902dd110 |
|
MD5 | 71a6666d9217a9f4c7f26e85443365cb |
|
BLAKE2b-256 | 81f2e848a25987abde6b1887708e8298bb44d4ef3fab5e18fb5a073b468ea9c7 |
Hashes for pypolyline-0.2.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 012f995fb71a4d207fb9f0ad4fb44234f74367efa3be2e2fb6c30dbaf3ccf35a |
|
MD5 | 952090617a6752ce9d9a7ceac694368c |
|
BLAKE2b-256 | 96572ae19143306353cf0c5d527a28fbda3bdba7ff8f6c82a946c2e76d0375b8 |
Hashes for pypolyline-0.2.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95801f714cb9a64e1c84092b5e57b36b5ccfcce1e3df8b6e1148cf876d055212 |
|
MD5 | 2ab48d75390198cf632d4352714afb68 |
|
BLAKE2b-256 | dc61c9b3d1b1283dbdb0a72b11985bf054f795d2fb1f068a72820375e564a61e |
Hashes for pypolyline-0.2.4-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da4815ea9087af09044c507d033f3de45f34e30299bcc7f54f73b5bac20554f0 |
|
MD5 | be6045722158e03b3cbfe4af317349cf |
|
BLAKE2b-256 | 0bd8a27b449e7ca1f57c87537143dfa624a13acd6749fea450aaa8c6e5992d5f |
Hashes for pypolyline-0.2.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b04d138833c36b042a39ec73ded51d03a949f65a8c80aa325e4406f509053a7e |
|
MD5 | c4b6d8a6c816ee99ded2b496879f4fd9 |
|
BLAKE2b-256 | 8e6b56c6375676d24133c46322882001e2b220b156f5857212d284e90003770d |
Hashes for pypolyline-0.2.4-cp36-cp36m-macosx_10_13_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 | 6d4baeabbfab742df0a68971883046720ee3471ab96cb5460a300a089a0f85b7 |
|
MD5 | 25d28b76c5b99be5dc4879e0b4944cf2 |
|
BLAKE2b-256 | f5bc1afe123f978ea4b3a437d3b2d60518660e77e8560d67435a7fd8cbef5a64 |
Hashes for pypolyline-0.2.4-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9af3cd19e68a8b87d867ca54fbb61a7363566a1a9d167f4a3dac1ccfa4296735 |
|
MD5 | 2d1f82cd8178f4f3cd85b70d4f855933 |
|
BLAKE2b-256 | a0dcfbc94e7ba78910255e4c53392ab4b519df83a6d085544c08fa8db077d021 |
Hashes for pypolyline-0.2.4-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 803b1614928e86e05368f657add8aa2f42e107bc6486400b688c39a8b13be4db |
|
MD5 | d94bf3474673ac1d0f6d844bd54d7281 |
|
BLAKE2b-256 | 3c65c969815a20bef690d5a6ffa6d6205f65a2ac862ae2a3e3d2f2dc81e60798 |
Hashes for pypolyline-0.2.4-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce072b238680220091d4ade8287eb41816df5385bc7de306c90d9c7693c48d1b |
|
MD5 | 42c40eeb894d5803cd76e5263ec813ff |
|
BLAKE2b-256 | 01b5eb2d47b6f90580ce9989f020c76614dc4e538b9d896c3a28b8a2694287d3 |
Hashes for pypolyline-0.2.4-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1300565a58166fef52c8e1b0504e975d9977caf66dadc65cff8aa1f57719f0f6 |
|
MD5 | a0b3df944066a707b2dc47e1680db905 |
|
BLAKE2b-256 | 46723eca43d5e42624c510ff1226fe415ecf1fa5dde371f657060bfe80309056 |
Hashes for pypolyline-0.2.4-cp27-cp27m-macosx_10_13_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 | 12d6441d5e9d3c1e0c38604e7fc040efd7334c06afd3dfcdc6a43027cd88505e |
|
MD5 | 47516a90bd51801b607f08886c924037 |
|
BLAKE2b-256 | f8188b954ba0ac6476783c2805a257420de7d70b94b18f351a78e472a51eea9f |