Crates.io | flexpolyline |
lib.rs | flexpolyline |
version | 1.0.0 |
source | src |
created_at | 2020-04-28 16:53:13.951211 |
updated_at | 2024-09-24 13:46:39.764548 |
description | Flexible Polyline encoding: a lossy compressed representation of a list of coordinate pairs or triples |
homepage | |
repository | https://github.com/heremaps/flexible-polyline.git |
max_upload_size | |
id | 235065 |
size | 40,897 |
The flexible polyline encoding is a lossy compressed representation of a list of coordinate pairs or coordinate triples. It achieves that by:
The encoding is a variant of Encoded Polyline Algorithm Format. The advantage of this encoding over the original are the following:
See Specification.
use flexpolyline::{Polyline, Precision};
// encode
let coordinates = vec![
(50.1022829, 8.6982122),
(50.1020076, 8.6956695),
(50.1006313, 8.6914960),
(50.0987800, 8.6875156),
];
let polyline = Polyline::Data2d {
coordinates,
precision2d: Precision::Digits5,
};
let encoded = polyline.encode().unwrap();
assert_eq!(encoded, "BFoz5xJ67i1B1B7PzIhaxL7Y");
// decode
let decoded = Polyline::decode("BFoz5xJ67i1B1B7PzIhaxL7Y").unwrap();
assert_eq!(
decoded,
Polyline::Data2d {
coordinates: vec![
(50.10228, 8.69821),
(50.10201, 8.69567),
(50.10063, 8.69150),
(50.09878, 8.68752)
],
precision2d: Precision::Digits5
}
);