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.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce559cba61ff13c6fd64adb1359350061aea02439e5dbe406929ce969f179179 |
|
MD5 | 5d847f34b6e25dd446339126ec5395d3 |
|
BLAKE2b-256 | f68087aeb557f892385c74e6a993ea68ded83f85c395e49c444c3090f4899997 |
Hashes for pypolyline-0.2.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72931992af0664bd6881cd3a1010c655162348b21933ba62114ea66ab2518932 |
|
MD5 | 436014c09ece26c52feafc9f32e5b2e3 |
|
BLAKE2b-256 | d1e9a4756f72ea202425fb8c0aeae7651872bdd4f91e966e9862209d1acdf159 |
Hashes for pypolyline-0.2.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58e028091b16d4b932edd5e02c39ac783f7d1e4e70ac31a379105ea732ba6924 |
|
MD5 | d11551e301dc25f9914481757d1f02ad |
|
BLAKE2b-256 | d3b3416bf9312c6820d356f1df48e5d491b9217a1da0cfd8835c501b1d9754e8 |
Hashes for pypolyline-0.2.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8eaadd3522babe1d73347a6edcce965e3c277e11707ea32a7cedd43ef5e2494 |
|
MD5 | 90efcce64d3114cf8f5b65793cafefb7 |
|
BLAKE2b-256 | 6ab4b2129314a6cb45d58ca6e9fbb22c95f5a07b0d37d112cdcfe0a686c5d4f4 |
Hashes for pypolyline-0.2.2-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 | 462705a7e8f78e88fe0803e3d14dc7d8d4a75eeed8b7bd1946ed695e034fe755 |
|
MD5 | 252180e5f4ab5f209e3ac9f571769b4c |
|
BLAKE2b-256 | f747b100ed170e247e4758df5630bee2fd391a595dda98ada6f35b139f57fa4e |
Hashes for pypolyline-0.2.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e7578021c80737cbaffb59561567ff049dfd3d1db854a3ce186d7aeddfbf187 |
|
MD5 | b96343ec9ab3dedee0181c18f818b9f9 |
|
BLAKE2b-256 | 6815a514fb77a0771b389c01b3398c1ae95ac499a1c428fd3812ac5f0e2b7a0b |
Hashes for pypolyline-0.2.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20e8f55f0c6466301eba301db24fa55bf442a8b51bf4f6e84fe79c9439b9bacf |
|
MD5 | 8e838a0a36276f998fe4bd56a61b0809 |
|
BLAKE2b-256 | 6a6e431f9c186e31a7b9676aea7b87cb75511fd53b7c8c172a500a0b1dfc5a63 |
Hashes for pypolyline-0.2.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e4f97ccdfc7439974a993f486711c3272eed550e402c7aacd0d04386c27134 |
|
MD5 | 7a97eaadbfe95b322a1545a99669cb4c |
|
BLAKE2b-256 | 039af57a41335933d50ac8f2235bb55b93076aa33f27007c3a1d0529bf1aa834 |
Hashes for pypolyline-0.2.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f38666898efde2a6f0e5c0bfd75d0148e84f891093edb50401391cb2470fee |
|
MD5 | b0d08a755fc90860484b01915c1fb800 |
|
BLAKE2b-256 | eb6cf82c643ed78a2249cdf5f628317df68e7920a76f1d70334d901cd53a3347 |
Hashes for pypolyline-0.2.2-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 | 8ac8c396dfe4e4368496cbc07c39ac8f661ba243c16d79a672c540459583580b |
|
MD5 | 0c3d8afdb04b4b7ff42243f9f9055b08 |
|
BLAKE2b-256 | eba8f447d471126baf2cce6aaa16305e9b1dc9308a04a3921ede10de17f2d855 |
Hashes for pypolyline-0.2.2-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ec9cafc3f1da1ddc2c63d4c91ecd3180fb37e774c6393142416bf7b877a1863 |
|
MD5 | 86937ae809c70c061042027b0b0b38a4 |
|
BLAKE2b-256 | cfb304468d3a9551b838ab22187ba90fd26e3f8b8723be3a3a2825ec1d3f92ee |
Hashes for pypolyline-0.2.2-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a75f68985f1243d231e3b23819e5b66229cbec2b2bc18bc290484e230e118a2d |
|
MD5 | e1e693e677465713ca22540713e7dec9 |
|
BLAKE2b-256 | 97982c998c5bdc3c8c6e59bee2148ed28f6007250a8ee567b87be140df263cb9 |
Hashes for pypolyline-0.2.2-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12cea49aebe8a8d4c8909d5ee373c4baf978676af4b667ee45231ce76a86f2c3 |
|
MD5 | 9e719174ebf75d11458ee5f85328e134 |
|
BLAKE2b-256 | a7f0165bdffe8200faafe2ba324a462594269f55d78224736ad699d82175bed8 |
Hashes for pypolyline-0.2.2-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc85d6f96005264bb08e2edfb649d88a73cf661d95a9933f9a7f41dfaf4a96e |
|
MD5 | 2fa297556505a3d9c1ade77b79c6d801 |
|
BLAKE2b-256 | b4d797e4de52927fad0199273375ab4ec1c0c2a65aa1ce7243b60c99d0f43034 |
Hashes for pypolyline-0.2.2-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 | 36722d1de6979fc98691303b0f09b0d3506005a7523760c96d895551b7e3c143 |
|
MD5 | bd50ebddb301f1c1f75fd136c3d9097c |
|
BLAKE2b-256 | 56e78533ac4c418b84e14fedee8ff318e5a032ab8c8c1c9685c12baa65e00e69 |