| Crates.io | rapidgeo-simplify |
| lib.rs | rapidgeo-simplify |
| version | 0.1.1 |
| created_at | 2025-09-01 17:33:01.703802+00 |
| updated_at | 2025-09-02 16:28:31.512134+00 |
| description | Douglas-Peucker polyline simplification with pluggable distance backends |
| homepage | https://github.com/gaker/rapidgeo |
| repository | https://github.com/gaker/rapidgeo |
| max_upload_size | |
| id | 1819967 |
| size | 97,142 |
Polyline simplification using the Douglas-Peucker algorithm with pluggable distance backends.
[dependencies]
rapidgeo-simplify = "0.1"
# For parallel processing support
rapidgeo-simplify = { version = "0.1", features = ["batch"] }
use rapidgeo_distance::LngLat;
use rapidgeo_simplify::{simplify_dp_into, SimplifyMethod};
let points = vec![
LngLat::new_deg(-122.4194, 37.7749), // San Francisco
LngLat::new_deg(-122.0, 37.5), // Detour
LngLat::new_deg(-121.5, 37.0), // Another point
LngLat::new_deg(-118.2437, 34.0522), // Los Angeles
];
let mut simplified = Vec::new();
let count = simplify_dp_into(
&points,
50000.0, // 50km tolerance
SimplifyMethod::GreatCircleMeters,
&mut simplified,
);
println!("Simplified from {} to {} points", points.len(), count);
The Douglas-Peucker algorithm simplifies polylines by removing points that don't significantly change the shape. Points are kept only if they deviate more than the specified tolerance from the simplified line. This implementation provides multiple distance calculation backends:
use rapidgeo_distance::LngLat;
use rapidgeo_simplify::{simplify_dp_mask, SimplifyMethod};
let points = vec![
LngLat::new_deg(-122.0, 37.0),
LngLat::new_deg(-121.5, 37.5),
LngLat::new_deg(-121.0, 37.0),
];
let mut mask = Vec::new();
simplify_dp_mask(
&points,
1000.0, // 1km tolerance
SimplifyMethod::GreatCircleMeters,
&mut mask,
);
// mask[i] is true if points[i] should be kept
for (i, &keep) in mask.iter().enumerate() {
if keep {
println!("Keep point {}: {:?}", i, points[i]);
}
}
use rapidgeo_simplify::batch::simplify_batch;
let polylines = vec![
vec![/* first polyline points */],
vec![/* second polyline points */],
];
let simplified = simplify_batch(
&polylines,
100.0,
SimplifyMethod::GreatCircleMeters,
);
batch feature)use rapidgeo_simplify::batch::simplify_batch_par;
let simplified = simplify_batch_par(
&polylines,
100.0,
SimplifyMethod::GreatCircleMeters,
);
Uses spherical distance calculations. Best for:
Projects to East-North-Up coordinates around the polyline's midpoint. Best for:
Direct coordinate subtraction. Best for:
simplify_dp_into(points, tolerance, method, output) - Simplify into output vectorsimplify_dp_mask(points, tolerance, method, mask) - Generate keep/drop masksimplify_batch(polylines, tolerance, method) - Process multiple polylinessimplify_batch_par(polylines, tolerance, method) - Parallel batch processingsimplify_dp_into_par(points, tolerance, method, output) - Parallel single polylineImplements the Douglas-Peucker algorithm:
The algorithm guarantees that:
batch featureLicensed under either of:
at your option.