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.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pypolyline-0.1.11-cp36-cp36m-manylinux1_x86_64.whl (695.8 kB view hashes)

Uploaded CPython 3.6m

pypolyline-0.1.11-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 (522.8 kB view hashes)

Uploaded CPython 3.6m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.11+ intel macOS 10.11+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

pypolyline-0.1.11-cp34-cp34m-win_amd64.whl (586.9 kB view hashes)

Uploaded CPython 3.4m Windows x86-64

pypolyline-0.1.11-cp27-cp27mu-manylinux1_x86_64.whl (680.1 kB view hashes)

Uploaded CPython 2.7mu

pypolyline-0.1.11-cp27-cp27m-win_amd64.whl (586.9 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

pypolyline-0.1.11-cp27-cp27m-win32.whl (648.8 kB view hashes)

Uploaded CPython 2.7m Windows x86

pypolyline-0.1.11-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 (522.9 kB view hashes)

Uploaded CPython 2.7m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.11+ intel macOS 10.11+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page