heremaps / flexible-polyline

Flexible Polyline encoding: a lossy compressed representation of a list of coordinate pairs or triples
MIT License
89 stars 76 forks source link

'Decode' function for python doesn't have 'precision' parameter #59

Closed alexisad closed 2 months ago

alexisad commented 1 year ago

Regarding this: https://developer.here.com/documentation/here-lanes/dev_guide/topics/hd-map-coordinate-encoding.html Platform data topologies have 7 digits of precision after the decimal point. But decode function by default returns only 5 digits after the decimal point.

Please add 'precision' parameter in the 'decode' function. Thanks

gtsystem commented 1 year ago

The decoded precision depends on the precision used when encoding the polyline. The encoder has a default of 5 digits of precision but there is a parameter to change that:

import flexpolyline as fp
input = [
    (50.1022829, 8.6982122),
    (50.1020076, 8.6956695),
    (50.1006313, 8.6914960),
    (50.0987800, 8.6875156),
]
res = fp.encode(input, precision=7)
print(fp.decode(res))

Output:

[(50.1022829, 8.6982122), (50.1020076, 8.6956695), (50.1006313, 8.691496), (50.09878, 8.6875156)]
frankgae commented 3 months ago

I recommend to close this feature request.

  1. As Giuseppe commented, the number of available decimals depends on the precision specified during encoding, not the decoding.
  2. "Reducing" the precision of the decoded coordinates is basically a 1-liner in Python. e.g:
        pts = fp.decode(s)
        pts = [(round(lat, 3), round(lng, 3)) for lat, lng in pts]

    This doesn't justify adding 'precision' and 'precision3d' arguments to the 'decode' method.