| Crates.io | rapidgeo-polyline |
| lib.rs | rapidgeo-polyline |
| version | 0.1.1 |
| created_at | 2025-09-01 17:34:06.207467+00 |
| updated_at | 2025-09-02 16:29:15.836702+00 |
| description | Fast Google Polyline Algorithm encoding/decoding for geographic coordinates |
| homepage | https://github.com/gaker/rapidgeo |
| repository | https://github.com/gaker/rapidgeo |
| max_upload_size | |
| id | 1819970 |
| size | 114,833 |
Fast Google Polyline Algorithm encoding/decoding for geographic coordinates.
[dependencies]
rapidgeo-polyline = "0.1"
For batch processing with parallel support:
[dependencies]
rapidgeo-polyline = { version = "0.1", features = ["batch"] }
use rapidgeo_polyline::{encode, decode};
use rapidgeo_distance::LngLat;
let coords = vec![
LngLat::new_deg(-120.2, 38.5),
LngLat::new_deg(-120.95, 40.7),
];
let encoded = encode(&coords, 5).unwrap();
let decoded = decode(&encoded, 5).unwrap();
Implements Google's Polyline Algorithm for encoding sequences of geographic coordinates into compact ASCII strings. Commonly used in mapping applications, route optimization, and GPS data storage.
Coordinate Order: All functions use longitude, latitude ordering (x, y).
use rapidgeo_polyline::{encode, decode};
use rapidgeo_distance::LngLat;
// Google's test vector
let coords = vec![
LngLat::new_deg(-120.2, 38.5),
LngLat::new_deg(-120.95, 40.7),
LngLat::new_deg(-126.453, 43.252),
];
let polyline = encode(&coords, 5).unwrap();
assert_eq!(polyline, "_p~iF~ps|U_ulLnnqC_mqNvxq`@");
let decoded = decode(&polyline, 5).unwrap();
assert_eq!(decoded.len(), 3);
Uses the Douglas-Peucker algorithm to reduce coordinate density while preserving route shape:
use rapidgeo_polyline::{encode_simplified, simplify_polyline};
use rapidgeo_simplify::SimplifyMethod;
use rapidgeo_distance::LngLat;
let detailed_route = vec![
LngLat::new_deg(-122.0, 37.0),
LngLat::new_deg(-122.01, 37.01), // Close intermediate point
LngLat::new_deg(-122.02, 37.02), // Close intermediate point
LngLat::new_deg(-122.1, 37.1),
];
// Encode with 1km simplification tolerance
let simplified = encode_simplified(
&detailed_route,
1000.0, // meters
SimplifyMethod::GreatCircleMeters,
5
).unwrap();
Process multiple polylines in parallel (requires batch feature):
#[cfg(feature = "batch")]
use rapidgeo_polyline::batch::{encode_batch, decode_batch};
#[cfg(feature = "batch")]
{
let routes = vec![
vec![LngLat::new_deg(-120.2, 38.5), LngLat::new_deg(-120.95, 40.7)],
vec![LngLat::new_deg(-126.453, 43.252), LngLat::new_deg(-122.4194, 37.7749)],
];
let encoded = encode_batch(&routes, 5).unwrap();
let decoded = decode_batch(&encoded, 5).unwrap();
}
encode(coords, precision) - Encode coordinates to polyline stringdecode(polyline, precision) - Decode polyline string to coordinatesencode_simplified(coords, tolerance, method, precision) - Encode with simplificationsimplify_polyline(polyline, tolerance, method, precision) - Simplify existing polylineencode_batch() - Parallel encoding of multiple coordinate sequencesdecode_batch() - Parallel decoding of multiple polylinesencode_simplified_batch() - Parallel encoding with simplificationValid range: 1-11
Licensed under either of Apache License, Version 2.0 or MIT license at your option.