InterpolateLine

Trait InterpolateLine 

Source
pub trait InterpolateLine<F: CoordFloat>:
    InterpolatePoint<F>
    + Length<F>
    + Sized {
    // Provided methods
    fn point_at_ratio_from_start<L: InterpolatableLine<F>>(
        &self,
        line: &L,
        ratio: F,
    ) -> L::Output { ... }
    fn point_at_ratio_from_end<L: InterpolatableLine<F>>(
        &self,
        line: &L,
        ratio: F,
    ) -> L::Output { ... }
    fn point_at_distance_from_start<L: InterpolatableLine<F>>(
        &self,
        line: &L,
        distance: F,
    ) -> L::Output { ... }
    fn point_at_distance_from_end<L: InterpolatableLine<F>>(
        &self,
        line: &L,
        distance: F,
    ) -> L::Output { ... }
}
Expand description

Interpolate a Point along a Line or LineString.

Related: See Densify if you’d like to interpolate potentially many points into a geometry.

Provided Methods§

Source

fn point_at_ratio_from_start<L: InterpolatableLine<F>>( &self, line: &L, ratio: F, ) -> L::Output

Returns a new point part way down the line.

§Params
  • line: A Line or LineString which implements InterpolatableLine.
  • ratio: the ratio of the total line length. It will be bounded between 0..1.
    • 0.0 will return the start of the line.
    • 1.0 will return the end of the line.
§Example
use geo::algorithm::{Haversine, Euclidean, InterpolateLine};
use geo::wkt;

let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));
let quarter_distance = Euclidean.point_at_ratio_from_start(&line_string, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(0. 5.)));

let quarter_distance = Haversine.point_at_ratio_from_start(&line_string, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(0. 4.961924877405399)), epsilon=1e-14);
Source

fn point_at_ratio_from_end<L: InterpolatableLine<F>>( &self, line: &L, ratio: F, ) -> L::Output

Returns a new point part way down the line, starting from the end of the line.

§Params
  • line: A Line or LineString which implements InterpolatableLine.
  • ratio: the ratio of the total line length. It will be bounded between 0..1.
    • 0.0 will return the end of the line.
    • 1.0 will return the start of the line.
§Example
use geo::algorithm::{Haversine, Euclidean, InterpolateLine};
use geo::wkt;

let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));
let quarter_distance = Euclidean.point_at_ratio_from_end(&line_string, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(5. 10.0)));

let quarter_distance = Haversine.point_at_ratio_from_end(&line_string, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(4.961333045966285 10.037420806650719)), epsilon=1e-14);
Source

fn point_at_distance_from_start<L: InterpolatableLine<F>>( &self, line: &L, distance: F, ) -> L::Output

Returns a new point distance from the start of the line.

§Params
  • line: A Line or LineString which implements InterpolatableLine.
  • distance: How far down the line. The units of distance depend on the metric space. Distance will be clamped so that the returned point will not be outside of line.
§Example
use geo::algorithm::{Haversine, Euclidean, InterpolateLine};
use geo::wkt;

let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));

// For Euclidean calculations, distance is in the same units as your points
let near_start = Euclidean.point_at_distance_from_start(&line_string, 0.5).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(0. 0.5)));

// For Haversine calculations, distance is in meters
let near_start = Haversine.point_at_distance_from_start(&line_string, 100_000.0).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(0. 0.899320363724538)), epsilon=1e-14);
Source

fn point_at_distance_from_end<L: InterpolatableLine<F>>( &self, line: &L, distance: F, ) -> L::Output

Returns a new point distance from the end of the line.

§Params
  • line: A Line or LineString which implements InterpolatableLine.
  • distance: How far down the line. The units of distance depend on the metric space. Distance will be clamped so that the returned point will not be outside of line.
§Example
use geo::algorithm::{Haversine, Euclidean, InterpolateLine};
use geo::wkt;

let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));

// For Euclidean calculations, distance is in the same units as your points
let near_start = Euclidean.point_at_distance_from_end(&line_string, 0.5).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(9.5 10.)));

// For Haversine calculations, distance is in meters
let near_start = Haversine.point_at_distance_from_end(&line_string, 100_000.0).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(9.086875463645015 10.012416322308656)), epsilon=1e-14);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F, MetricSpace> InterpolateLine<F> for MetricSpace
where F: CoordFloat, MetricSpace: InterpolatePoint<F> + Length<F> + Sized,