#codec #encoded #decoding #google #format #encoding

polyline

Encoder and decoder for the Google Encoded Polyline format

13 releases (breaking)

0.10.1 May 10, 2023
0.10.0 Mar 12, 2023
0.9.0 Feb 5, 2021
0.8.0 Jun 23, 2020
0.4.0 Jul 17, 2016

#79 in Geospatial

Download history 1424/week @ 2023-12-11 1154/week @ 2023-12-18 967/week @ 2023-12-25 508/week @ 2024-01-01 1240/week @ 2024-01-08 1657/week @ 2024-01-15 1382/week @ 2024-01-22 1458/week @ 2024-01-29 1439/week @ 2024-02-05 1496/week @ 2024-02-12 1920/week @ 2024-02-19 1659/week @ 2024-02-26 1293/week @ 2024-03-04 1309/week @ 2024-03-11 1507/week @ 2024-03-18 1576/week @ 2024-03-25

5,754 downloads per month
Used in 6 crates

MIT/Apache

31KB
167 lines

polyline

Crates.io Build Status

Google Encoded Polyline encoding & decoding in Rust.

A Note on Coordinate Order

This crate uses Coord and LineString types from the geo-types crate, which encodes coordinates in (x, y) order. The Polyline algorithm and first-party documentation assumes the opposite coordinate order. It is thus advisable to pay careful attention to the order of the coordinates you use for encoding and decoding.

Documentation


lib.rs:

Google Encoded Polyline encoding & decoding in Rust

Polyline is a lossy compression algorithm that allows you to store a series of coordinates as a single string.

Example

use polyline;
use geo_types::line_string;

let coord = line_string![(x: -120.2, y: 38.5), (x: -120.95, y: 40.7), (x: -126.453, y: 43.252)];
let output = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
let result = polyline::encode_coordinates(coord, 5).unwrap();
assert_eq!(result, output)

A Note on Coordinate Order

This crate uses Coordinate and LineString types from the geo-types crate, which encodes coordinates in (x, y) order. The Polyline algorithm and first-party documentation assumes the opposite coordinate order. It is thus advisable to pay careful attention to the order of the coordinates you use for encoding and decoding.

Dependencies

~755KB
~15K SLoC