pub trait LineStringSegmentize {
    // Required method
    fn line_segmentize(&self, n: usize) -> Option<MultiLineString>;
}
Expand description

Segments a LineString into n equal length LineStrings as a MultiLineString. None will be returned when n is equal to 0 or when a point cannot be interpolated on a Line segment.

Examples

use geo::{LineString, MultiLineString, LineStringSegmentize, Coord};
// Create a simple line string
let lns: LineString<f64> = vec![[0.0, 0.0], [1.0, 2.0], [3.0, 6.0]].into();
// Segment it into 6 LineStrings inside of a MultiLineString
let segmentized = lns.line_segmentize(6).unwrap();

// Recreate the MultiLineString from scratch
// this is the inner vector used to create the MultiLineString
let all_lines = vec![
    LineString::new(vec![Coord { x: 0.0, y: 0.0 }, Coord { x: 0.5, y: 1.0 }]),
    LineString::new(vec![Coord { x: 0.5, y: 1.0 }, Coord { x: 1.0, y: 2.0 }]),
    LineString::new(vec![Coord { x: 1.0, y: 2.0 }, Coord { x: 1.5, y: 3.0 }]),
    LineString::new(vec![Coord { x: 1.5, y: 3.0 }, Coord { x: 2.0, y: 4.0 }]),
    LineString::new(vec![Coord { x: 2.0, y: 4.0 }, Coord { x: 2.5, y: 5.0 }]),
    LineString::new(vec![Coord { x: 2.5, y: 5.0 }, Coord { x: 3.0, y: 6.0 }])
    ];

// Create the MultiLineString
let mlns = MultiLineString::new(all_lines);

// Compare the two
assert_eq!(mlns, segmentized);

Required Methods§

Implementors§