Skip to main content

Fast Google Polyline encoding and decoding using Rust FFI

Project description

Installation

pip install pypolyline

Please use a recent (>= 8.1.2) version of pip.

Supported Python Versions

  • Python 2.7 (*nix and Windows)
  • Python 3.4 (Windows)
  • Python 3.6 (*nix)

Supported Platforms

  • Linux (manylinux1-compatible)
  • OS X
  • Windows 32-bit / 64-bit

Usage

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.DecodingError

Attempts to encode invalid coordinates will throw util.EncodingError

Cython Module

If you’re comfortable with a lack of built-in exceptions, you may use the compiled Cython version of the functions, instead, giving a 2x 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.

The C++ version runs around 18x faster than the pure Python version.
The Rust + Cython version runs around 54x faster than the pure Python version.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pypolyline-0.1.17-cp27-cp27m-macosx_10_6_intel.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 (345.2 kB) Copy SHA256 hash SHA256 Wheel cp27
pypolyline-0.1.17-cp27-cp27mu-manylinux1_x86_64.whl (458.5 kB) Copy SHA256 hash SHA256 Wheel cp27
pypolyline-0.1.17-cp27-cp27m-win32.whl (278.8 kB) Copy SHA256 hash SHA256 Wheel cp27
pypolyline-0.1.17-cp27-cp27m-win_amd64.whl (298.4 kB) Copy SHA256 hash SHA256 Wheel cp27
pypolyline-0.1.17-cp36-cp36m-macosx_10_6_intel.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 (344.1 kB) Copy SHA256 hash SHA256 Wheel cp36
pypolyline-0.1.17-cp36-cp36m-manylinux1_x86_64.whl (478.1 kB) Copy SHA256 hash SHA256 Wheel cp36
pypolyline-0.1.17-cp36-cp36m-win32.whl (279.0 kB) Copy SHA256 hash SHA256 Wheel cp36
pypolyline-0.1.17-cp36-cp36m-win_amd64.whl (299.8 kB) Copy SHA256 hash SHA256 Wheel cp36
pypolyline-0.1.17-cp37-cp37m-macosx_10_6_intel.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 (341.3 kB) Copy SHA256 hash SHA256 Wheel cp37
pypolyline-0.1.17-cp37-cp37m-manylinux1_x86_64.whl (477.4 kB) Copy SHA256 hash SHA256 Wheel cp37

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page