pypolyline

0.5.6 · active · verified Fri Apr 17

pypolyline provides fast Google Polyline encoding and decoding functionalities, leveraging Rust FFI for performance. It is currently at version 0.5.6 and maintains an active, albeit irregular, release cadence with minor updates addressing improvements and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to encode a list of (latitude, longitude) tuples into a Google Polyline string and decode a Polyline string back into a list of points. The `precision` parameter is crucial for correct encoding/decoding, with `5` being standard for Google Polylines.

from pypolyline.codec import decode, encode

# Example data
test_polyline = "y~z_@mfhV~tqNvxq`@"
test_points = [(38.5, -120.2), (40.7, -120.95), (43.252, -126.453)]

# Encoding points to a polyline string (Google Polyline typically uses precision=5)
encoded_polyline = encode(test_points, precision=5)
print(f"Encoded Polyline: {encoded_polyline}")

# Decoding a polyline string back to points
decoded_points = decode(test_polyline, precision=5)
print(f"Decoded Points: {decoded_points}")

view raw JSON →