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) - macOS
- 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
Citing Pypolyline
If Pypolyline has been significant in your research, and you would like to acknowledge the project in your academic publication, we suggest citing it as follows (example in APA style, 7th edition):
Hügel, S. (2021). Pypolyline (Version X.Y.Z) [Computer software]. https://doi.org/10.5281/zenodo.5774925
In Bibtex format:
@software{Hugel_Pypolyline_2021,
author = {Hügel, Stephan},
doi = {10.5281/zenodo.5774925},
license = {MIT},
month = {12},
title = {{Pypolyline}},
url = {https://github.com/urschrei/simplification},
version = {X.Y.Z},
year = {2021}
}
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.75-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74bbcb136d7e5b22281d8d5c0b58e302d7887853f7dea31b1bc70fed7144489d |
|
MD5 | c7e3e5ffab623f12c46a35459ba6a8f2 |
|
BLAKE2b-256 | 1c747f6baf57b4e98c63f9cc5c48d6504a53d658a590a48d987ed45e88027bab |
Hashes for pypolyline-0.2.75-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 013cd014a65acf30cadd1f96cb666bf0f71cc1429af5d75381d1a44b001fbb30 |
|
MD5 | ef05d4e0bba67108b442b814f6c551ba |
|
BLAKE2b-256 | 9c7c84b16a8b25d67b4c03d4ccec74f5b023549f265320b121a888743b9dce19 |
Hashes for pypolyline-0.2.75-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5afaf44698a17c684517f3ac1fd94e42e47b6708183b5af1e68c3276a986e03 |
|
MD5 | 8ec24d6c3ec880e6ed62f2be5919142b |
|
BLAKE2b-256 | b239ab49d636d7e52f416372eb72d015e0e6adabb67d2956012534ceaac0eac9 |
Hashes for pypolyline-0.2.75-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec7ec0d257e548b3c79670340e53b73effa976c4248eef83f073716a2f9eb7ff |
|
MD5 | adaa029d75709db44fb84991814e9cf5 |
|
BLAKE2b-256 | c2f5cb85533d01d60df4a3b2247388b748798eaecd0a2fa3fdff672b4b5961f3 |
Hashes for pypolyline-0.2.75-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9ac16a21354ec257a02b6f80c62ffd41f47ed6b671064f8b9a6a14201d424fe |
|
MD5 | 40e346b9d4ad066482f00c31d5c95916 |
|
BLAKE2b-256 | 30082f7723c8ce0e94c2102fb7407ecda4777824b33eff32838df732c210c605 |
Hashes for pypolyline-0.2.75-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 046f2eabd414597b9ee1554cf34e93b13df67b29865b51a178172e8429e13a71 |
|
MD5 | e0aa0db0dfde79618d052d6e327ad2f4 |
|
BLAKE2b-256 | cdd50c56a4de6913cba550c2c9d97bb484195b7f961e28c35607154a387c67a6 |
Hashes for pypolyline-0.2.75-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 444172641a720b7484a7ca9e3375cdd3ef7fb154b174429fd1368b16f5b59472 |
|
MD5 | be1f493a8dff40916bc2dc0cc2884103 |
|
BLAKE2b-256 | 3a019e11ea0e16afcaa5a20f441e9ed54cc82f321d6bfabc5fbc59e5675782f8 |
Hashes for pypolyline-0.2.75-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1862003a14da80f949e766e8ba0b1384be207775ec544e27dc85acda2dba256b |
|
MD5 | 8a1e0b3dcf1a807c93cc6ec30eb3b70e |
|
BLAKE2b-256 | de537a167d357c34d773236b3d0f8c8a712b7b812a38789b2d5e1867b6235e32 |
Hashes for pypolyline-0.2.75-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 240c96b425b2ec2c906a6eaf0ad426527ef16efc554c8fcc64fe8ab1c0e30078 |
|
MD5 | d7e06fc6854241c2844f71d9dee23a63 |
|
BLAKE2b-256 | f7aba999efbe3762c00fcef73f46506c175c3eec966116f11c17f80c36ff6591 |
Hashes for pypolyline-0.2.75-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a2ee2d9538a84a139b6320bbc7c3067d0d994fb8568cc7b0fce3e31c8c9e8e6 |
|
MD5 | 6374fef42ab7e5040ff6da51e2529216 |
|
BLAKE2b-256 | 615f8ec0a47c84ae792095563503af756288aeed8d1e19fe61fb97d39051c5de |
Hashes for pypolyline-0.2.75-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 657430ae724f92a44d575679f140ac74e4b8dc9784b2452e358f0237eb41a821 |
|
MD5 | 0578e62cb99691e8c769d541d830f0de |
|
BLAKE2b-256 | aee09d44e1c4ef267dfb82c7c8523d8b3d36477e526aa94b68b478c5af9f53e3 |