Crate rapidgeo_simplify

Crate rapidgeo_simplify 

Source
Expand description

Douglas-Peucker polyline simplification with pluggable distance backends.

This crate implements the Douglas-Peucker algorithm for simplifying polylines while preserving their essential shape characteristics. The algorithm reduces the number of points in a polyline by removing points that don’t significantly contribute to the overall shape, based on a distance threshold.

§Quick Start

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,
);

assert_eq!(count, simplified.len());
// Endpoints are always preserved
assert_eq!(simplified[0], points[0]);
assert_eq!(simplified[count - 1], points[points.len() - 1]);

§Distance Methods

§Batch Processing

Enable the batch feature for parallel processing of multiple polylines:

[dependencies]
rapidgeo-simplify = { version = "0.1", features = ["batch"] }

Modules§

batch
Batch and parallel processing for multiple polylines.
dp
Core Douglas-Peucker simplification algorithm implementation.
xt
Cross-track distance calculation implementations.

Enums§

SimplifyMethod
Distance calculation method for Douglas-Peucker simplification.

Functions§

simplify_dp_into
Simplify a polyline using the Douglas-Peucker algorithm.
simplify_dp_mask
Generate a boolean mask indicating which points to keep during simplification.