Skip to main content

A Python implementation of Google's Encoded Polyline Algorithm Format.

Project description

http://img.shields.io/pypi/v/polyline.svg?style=flat Documentation Status Build

polyline is a Python implementation of Google’s Encoded Polyline Algorithm Format. It is essentially a port of Mapbox polyline with some additional features.

Installation

polyline can be installed using pip:

$ pip install polyline

Starting from v2.0.0 only Python 3.7 and above is supported. For Python 2 support, please install v1.4.0:

$ pip install polyline==1.4.0

API Documentation

Encoding

To get the encoded polyline representation of a given set of (lat, lon) coordinates:

import polyline
polyline.encode([(38.5, -120.2), (40.7, -120.9), (43.2, -126.4)], 5)

This should return _p~iF~ps|U_ulL~ugC_hgN~eq`@.

You can set the required precision with the optional precision parameter. The default value is 5.

You can encode (lon, lat) tuples by setting geojson=True.

Decoding

To get a set of coordinates represented by a given encoded polyline string:

import polyline
polyline.decode('u{~vFvyys@fS]', 5)

This should return [(40.63179, -8.65708), (40.62855, -8.65693)] in (lat, lon) order.

You can set the required precision with the optional precision parameter. The default value is 5.

You can decode into (lon, lat) tuples by setting geojson=True.

Development

All installation and development dependencies are fully specified in pyproject.toml. The project.optional-dependencies object is used to specify optional requirements for various development tasks. This makes it possible to specify additional options when performing installation using pip:

python -m pip install .[dev]

Documentation

The documentation can be generated automatically from the source files using Sphinx:

python -m sphinx.cmd.build -b html docs docs/_build/html

Testing and Conventions

All unit tests are executed and their coverage is measured when using pytest:

python -m pytest

Style conventions are enforced using Pylint:

python -m pylint polyline

Contributions

In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.

Versioning

Beginning with version 0.1.0, the version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.

Publishing

This library can be published as a package on PyPI by a package maintainer. Ensure that the correct version number appears in pyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an automation rule that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ?.?.? with the version number):

git tag ?.?.?
git push origin ?.?.?

Remove any old build/distribution files. Then, package the source into a distribution archive:

rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .

Finally, upload the package distribution archive to PyPI:

python -m twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polyline-2.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polyline-2.0.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file polyline-2.0.0.tar.gz.

File metadata

  • Download URL: polyline-2.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for polyline-2.0.0.tar.gz
Algorithm Hash digest
SHA256 1492b8fcadc2143f8aedc673d3c6d95df45131f1c62eb8d51c8183b24e771486
MD5 0be22ba7e5b7f47afb717f90184a1d37
BLAKE2b-256 d6a8343437618741b8e60e2621c279aa05d39d3908d0c81f253d2f162b289bff

See more details on using hashes here.

File details

Details for the file polyline-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: polyline-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for polyline-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45c9c0e8c0814a17df78390e3196cd47f6bc69697cd8a83f00d527c72f4d2a88
MD5 8cb081d3d93995489ff37720897dd042
BLAKE2b-256 e38d937825a2b21e91858d4f37e0b7e332726123f88d1979d8d9b669b085a21b

See more details on using hashes here.

Supported by

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