rapidgeo-polyline
Fast Google Polyline Algorithm encoding/decoding for geographic coordinates.
Installation
[]
= "0.1"
For batch processing with parallel support:
[]
= { = "0.1", = ["batch"] }
Quick Start
use ;
use LngLat;
let coords = vec!;
let encoded = encode.unwrap;
let decoded = decode.unwrap;
What This Does
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).
Examples
Basic Encoding/Decoding
use ;
use LngLat;
// Google's test vector
let coords = vec!;
let polyline = encode.unwrap;
assert_eq!;
let decoded = decode.unwrap;
assert_eq!;
Route Simplification
Uses the Douglas-Peucker algorithm to reduce coordinate density while preserving route shape:
use ;
use SimplifyMethod;
use LngLat;
let detailed_route = vec!;
// Encode with 1km simplification tolerance
let simplified = encode_simplified.unwrap;
Batch Processing
Process multiple polylines in parallel (requires batch feature):
use ;
API
Core Functions
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 polyline
Batch Functions (feature = "batch")
encode_batch()- Parallel encoding of multiple coordinate sequencesdecode_batch()- Parallel decoding of multiple polylinesencode_simplified_batch()- Parallel encoding with simplification
Precision
- 5 (default): ~1 meter accuracy, standard for most mapping applications
- 6: ~10 centimeter accuracy, used for high-precision applications
Valid range: 1-11
Performance
- Encoding: ~2-4 million coordinates/second
- Decoding: ~3-5 million coordinates/second
- Memory: O(n) where n = number of coordinates
- Batch processing automatically uses parallel processing for >100 polylines
Limitations
- Coordinates must be within valid WGS84 bounds (±180° longitude, ±90° latitude)
- No support for 3D coordinates (elevation)
- Precision limited to 11 decimal places
- Does not handle coordinate reference system transformations
Algorithm References
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.