FlexPolyline
raw JSON → 0.1.0 verified Mon Apr 27 auth: no python
Flexible Polyline encoding, a lossy compressed representation of a list of coordinate pairs or triples, based on the HERE Flexible Polyline encoding standard. Current version: 0.1.0. Release cadence: sporadic, maintained by HERE Technologies.
pip install flexpolyline Common errors
error ValueError: Unknown third dimension value: 3 ↓
cause The third_dim parameter must be 0 (none), 1 (elevation), or 2 (elevation and extrude).
fix
Use allowed values: third_dim=0, third_dim=1, or third_dim=2.
error TypeError: a float is required ↓
cause Coordinates contain non-numeric values or are not in the correct format.
fix
Ensure all coordinate values are floats and input is a list of tuples of numbers.
error flexpolyline._flexpolyline.PolylineDecoderError: Invalid character in input ↓
cause The encoded string contains invalid characters (e.g., spaces, special symbols).
fix
Pass only the valid encoded polyline string; remove whitespace or unexpected characters.
Warnings
gotcha The decode function returns a list of tuples, not a list of lists or numpy arrays. ↓
fix Access coordinates as tuple elements, e.g., lat, lon = decoded[0].
gotcha Coordinates must be in (lat, lon) order, not (lon, lat). ↓
fix Ensure your input tuples are (latitude, longitude).
gotcha The library uses a specific precision (default 5) which may cause loss of detail for high-precision coordinates. ↓
fix For higher precision, pass the precision parameter to encode: encode(coords, precision=7).
Imports
- encode
from flexpolyline import encode - decode
from flexpolyline import decode
Quickstart
from flexpolyline import encode, decode
# Coordinates as list of (lat, lon) pairs
coordinates = [(52.5, 13.35), (52.515, 13.36), (52.520, 13.37)]
# Encode with default precision (5) and 2D (third dimension none)
encoded = encode(coordinates)
print(encoded) # e.g., 'BF05xgKuy7lB8s7B'
# Decode back to coordinates
decoded = decode(encoded)
print(decoded) # [(52.5, 13.35), (52.515, 13.36), (52.520, 13.37)]