Implementation of the Google polyline algorithm.
Up to 60x faster than the polyline package.
make bench
made on a Apple M1 computer.
fast_polyline: 10.606ms
polyline: 613.5ms
fast_polyline is 57.8 times faster.
fast_polyline: 23.447ms
polyline: 425.96ms
fast_polyline is 18.2 times faster.
pip install fast_polyline
or in your requirements.txt
:
fast_polyline~=0.2.0
import fast_polyline
fast_polyline.encode([[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]])
# => "_p~iF~ps|U_ulLnnqC_mqNvxq`@"
fast_polyline.decode("_p~iF~ps|U_ulLnnqC_mqNvxq`@")
# => [[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]
Use a different precision
Default precision is 5
decimals, to use a precision of 6
:
fast_polyline.encode([[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]], 6)
# => "_izlhA~rlgdF_{geC~ywl@_kwzCn`{nI"
fast_polyline.decode("_izlhA~rlgdF_{geC~ywl@_kwzCn`{nI", 6)
# => [[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]
The precision max is 13
. And I advanced against using it
since it is already way too precise.
Encoder
and Decoder
modules are deprec
git clone git@github.com:BuonOmo/fast-polyline.py
cd fast-polyline.py
make # show all commands you might need
# Implement a feature, resolve a bug...
make lint
make test
git commit "feat: respect conventional commits"
# Make a PR
And here's the Python C ABI doc.
Please see the LICENSE file.