Struct geo::LineString[][src]

pub struct LineString<T>(pub Vec<Coordinate<T>, Global>)
where
    T: CoordNum
;

An ordered collection of two or more Coordinates, representing a path between locations.

Semantics

A LineString is closed if it is empty, or if the first and last coordinates are the same. The boundary of a LineString is empty if closed, and otherwise the end points. The interior is the (infinite) set of all points along the linestring not including the boundary. A LineString is simple if it does not intersect except possibly at the first and last coordinates. A simple and closed LineString is a LinearRing as defined in the OGC-SFA (but is not a separate type here).

Validity

A LineString is valid if it is either empty or contains 2 or more coordinates. Further, a closed LineString must not self intersect. Note that the validity is not enforced, and the operations and predicates are undefined on invalid linestrings.

Examples

Create a LineString by calling it directly:

use geo_types::{Coordinate, LineString};

let line_string = LineString(vec![
    Coordinate { x: 0., y: 0. },
    Coordinate { x: 10., y: 0. },
]);

Create a LineString with the line_string! macro:

use geo_types::line_string;

let line_string = line_string![
    (x: 0., y: 0.),
    (x: 10., y: 0.),
];

Converting a Vec of Coordinate-like things:

use geo_types::LineString;

let line_string: LineString<f32> = vec![(0., 0.), (10., 0.)].into();
use geo_types::LineString;

let line_string: LineString<f64> = vec![[0., 0.], [10., 0.]].into();

Or collecting from a Coordinate iterator

use geo_types::{Coordinate, LineString};

let mut coords_iter =
    vec![Coordinate { x: 0., y: 0. }, Coordinate { x: 10., y: 0. }].into_iter();

let line_string: LineString<f32> = coords_iter.collect();

You can iterate over the coordinates in the LineString:

use geo_types::{Coordinate, LineString};

let line_string = LineString(vec![
    Coordinate { x: 0., y: 0. },
    Coordinate { x: 10., y: 0. },
]);

for coord in line_string {
    println!("Coordinate x = {}, y = {}", coord.x, coord.y);
}

You can also iterate over the coordinates in the LineString as Points:

use geo_types::{Coordinate, LineString};

let line_string = LineString(vec![
    Coordinate { x: 0., y: 0. },
    Coordinate { x: 10., y: 0. },
]);

for point in line_string.points_iter() {
    println!("Point x = {}, y = {}", point.x(), point.y());
}

Implementations

impl<T> LineString<T> where
    T: CoordNum
[src]

pub fn points_iter(&self) -> PointsIter<'_, T>[src]

Return an iterator yielding the coordinates of a LineString as Points

pub fn into_points(self) -> Vec<Point<T>, Global>[src]

Return the coordinates of a LineString as a Vec of Points

pub fn lines(&self) -> impl ExactSizeIterator + Iterator<Item = Line<T>>[src]

Return an iterator yielding one Line for each line segment in the LineString.

Examples

use geo_types::{Coordinate, Line, LineString};

let mut coords = vec![(0., 0.), (5., 0.), (7., 9.)];
let line_string: LineString<f32> = coords.into_iter().collect();

let mut lines = line_string.lines();
assert_eq!(
    Some(Line::new(
        Coordinate { x: 0., y: 0. },
        Coordinate { x: 5., y: 0. }
    )),
    lines.next()
);
assert_eq!(
    Some(Line::new(
        Coordinate { x: 5., y: 0. },
        Coordinate { x: 7., y: 9. }
    )),
    lines.next()
);
assert!(lines.next().is_none());

pub fn triangles(&self) -> impl ExactSizeIterator + Iterator<Item = Triangle<T>>[src]

An iterator which yields the coordinates of a LineString as Triangles

pub fn close(&mut self)[src]

Close the LineString. Specifically, if the LineString has at least one coordinate, and the value of the first coordinate does not equal the value of the last coordinate, then a new coordinate is added to the end with the value of the first coordinate.

pub fn num_coords(&self) -> usize[src]

👎 Deprecated:

Use geo::algorithm::coords_iter::CoordsIter::coords_count instead

Return the number of coordinates in the LineString.

Examples

use geo_types::LineString;

let mut coords = vec![(0., 0.), (5., 0.), (7., 9.)];
let line_string: LineString<f32> = coords.into_iter().collect();
assert_eq!(3, line_string.num_coords());

pub fn is_closed(&self) -> bool[src]

Checks if the linestring is closed; i.e. it is either empty or, the first and last points are the same.

Examples

use geo_types::LineString;

let mut coords = vec![(0., 0.), (5., 0.), (0., 0.)];
let line_string: LineString<f32> = coords.into_iter().collect();
assert!(line_string.is_closed());

Note that we diverge from some libraries (JTS et al), which have a LinearRing type, separate from LineString. Those libraries treat an empty LinearRing as closed, by definition, while treating an empty LineString as open. Since we don’t have a separate LinearRing type, and use a LineString in its place, we adopt the JTS LinearRing is_closed behavior in all places, that is, we consider an empty LineString as closed.

This is expected when used in the context of a Polygon.exterior and elswhere; And there seems to be no reason to maintain the separate behavior for LineStrings used in non-LinearRing contexts.

Trait Implementations

impl<T> AbsDiffEq<LineString<T>> for LineString<T> where
    T: AbsDiffEq<T, Epsilon = T> + CoordNum
[src]

type Epsilon = T

Used for specifying relative comparisons.

pub fn abs_diff_eq(
    &self,
    other: &LineString<T>,
    epsilon: <LineString<T> as AbsDiffEq<LineString<T>>>::Epsilon
) -> bool
[src]

Equality assertion with an absolute limit.

Examples

use geo_types::LineString;

let mut coords_a = vec![(0., 0.), (5., 0.), (7., 9.)];
let a: LineString<f32> = coords_a.into_iter().collect();

let mut coords_b = vec![(0., 0.), (5., 0.), (7.001, 9.)];
let b: LineString<f32> = coords_b.into_iter().collect();

approx::assert_relative_eq!(a, b, epsilon=0.1)

impl<T> Area<T> for LineString<T> where
    T: CoordNum
[src]

impl<T> BoundingRect<T> for LineString<T> where
    T: CoordNum
[src]

type Output = Option<Rect<T>>

fn bounding_rect(&self) -> Self::Output[src]

Return the BoundingRect for a LineString

impl<T> Centroid for LineString<T> where
    T: GeoFloat
[src]

type Output = Option<Point<T>>

impl<T> Clone for LineString<T> where
    T: Clone + CoordNum
[src]

impl<F: GeoFloat> ClosestPoint<F, Point<F>> for LineString<F>[src]

impl<T> ConcaveHull for LineString<T> where
    T: GeoFloat + RTreeNum
[src]

type Scalar = T

impl<T> Contains<Coordinate<T>> for LineString<T> where
    T: GeoNum
[src]

impl<T> Contains<Line<T>> for LineString<T> where
    T: GeoNum
[src]

impl<F> Contains<LineString<F>> for MultiPolygon<F> where
    F: GeoFloat
[src]

impl<T> Contains<LineString<T>> for Line<T> where
    T: GeoNum
[src]

impl<T> Contains<LineString<T>> for LineString<T> where
    T: GeoNum
[src]

impl<T> Contains<LineString<T>> for Polygon<T> where
    T: GeoFloat
[src]

impl<T> Contains<Point<T>> for LineString<T> where
    T: GeoNum
[src]

impl<T> ConvexHull for LineString<T> where
    T: GeoNum
[src]

type Scalar = T

impl<T> CoordinatePosition for LineString<T> where
    T: GeoNum
[src]

type Scalar = T

impl<'a, T: CoordNum + 'a> CoordsIter<'a> for LineString<T>[src]

type Iter = Copied<Iter<'a, Coordinate<T>>>

type ExteriorIter = Self::Iter

type Scalar = T

fn coords_count(&'a self) -> usize[src]

Return the number of coordinates in the LineString.

impl<T> Debug for LineString<T> where
    T: Debug + CoordNum
[src]

impl<T> Eq for LineString<T> where
    T: Eq + CoordNum
[src]

impl<T> EuclideanDistance<T, Line<T>> for LineString<T> where
    T: GeoFloat + FloatConst + Signed + RTreeNum
[src]

LineString to Line

impl<T> EuclideanDistance<T, LineString<T>> for Point<T> where
    T: GeoFloat
[src]

fn euclidean_distance(&self, linestring: &LineString<T>) -> T[src]

Minimum distance from a Point to a LineString

impl<T> EuclideanDistance<T, LineString<T>> for Line<T> where
    T: GeoFloat + FloatConst + Signed + RTreeNum
[src]

Line to LineString

impl<T> EuclideanDistance<T, LineString<T>> for LineString<T> where
    T: GeoFloat + Signed + RTreeNum
[src]

LineString-LineString distance

impl<T> EuclideanDistance<T, LineString<T>> for Polygon<T> where
    T: GeoFloat + FloatConst + Signed + RTreeNum
[src]

Polygon to LineString distance

impl<T> EuclideanDistance<T, Point<T>> for LineString<T> where
    T: GeoFloat
[src]

fn euclidean_distance(&self, point: &Point<T>) -> T[src]

Minimum distance from a LineString to a Point

impl<T> EuclideanDistance<T, Polygon<T>> for LineString<T> where
    T: GeoFloat + FloatConst + Signed + RTreeNum
[src]

LineString to Polygon

impl<T> EuclideanLength<T, LineString<T>> for LineString<T> where
    T: CoordFloat + Sum
[src]

impl<T> FrechetDistance<T, LineString<T>> for LineString<T> where
    T: GeoFloat + FromPrimitive
[src]

impl<T> From<Line<T>> for LineString<T> where
    T: CoordNum
[src]

impl<T> From<LineString<T>> for Geometry<T> where
    T: CoordNum
[src]

impl<T, IC> From<Vec<IC, Global>> for LineString<T> where
    T: CoordNum,
    IC: Into<Coordinate<T>>, 
[src]

Turn a Vec of Point-like objects into a LineString.

impl<T, IC> FromIterator<IC> for LineString<T> where
    T: CoordNum,
    IC: Into<Coordinate<T>>, 
[src]

Turn an iterator of Point-like objects into a LineString.

impl GeodesicLength<f64, LineString<f64>> for LineString<f64>[src]

impl<C: CoordNum> HasDimensions for LineString<C>[src]

fn boundary_dimensions(&self) -> Dimensions[src]

use geo_types::line_string;
use geo::algorithm::dimensions::{HasDimensions, Dimensions};

let ls = line_string![(x: 0.,  y: 0.), (x: 0., y: 1.), (x: 1., y: 1.)];
assert_eq!(Dimensions::ZeroDimensional, ls.boundary_dimensions());

let ls = line_string![(x: 0.,  y: 0.), (x: 0., y: 1.), (x: 1., y: 1.), (x: 0., y: 0.)];
assert_eq!(Dimensions::Empty, ls.boundary_dimensions());

impl<T> Hash for LineString<T> where
    T: Hash + CoordNum
[src]

impl<T> HaversineLength<T, LineString<T>> for LineString<T> where
    T: CoordFloat + FromPrimitive
[src]

impl<T> Index<usize> for LineString<T> where
    T: CoordNum
[src]

type Output = Coordinate<T>

The returned type after indexing.

impl<T> IndexMut<usize> for LineString<T> where
    T: CoordNum
[src]

impl<T, G> Intersects<G> for LineString<T> where
    T: CoordNum,
    Line<T>: Intersects<G>, 
[src]

impl<T> Intersects<LineString<T>> for Coordinate<T> where
    LineString<T>: Intersects<Coordinate<T>>,
    T: CoordNum
[src]

impl<T> Intersects<LineString<T>> for Line<T> where
    LineString<T>: Intersects<Line<T>>,
    T: CoordNum
[src]

impl<T> Intersects<LineString<T>> for Polygon<T> where
    LineString<T>: Intersects<Polygon<T>>,
    T: CoordNum
[src]

impl<'a, T> IntoIterator for &'a mut LineString<T> where
    T: CoordNum
[src]

Mutably iterate over all the Coordinates in this LineString.

type Item = &'a mut Coordinate<T>

The type of the elements being iterated over.

type IntoIter = IterMut<'a, Coordinate<T>>

Which kind of iterator are we turning this into?

impl<T> IntoIterator for LineString<T> where
    T: CoordNum
[src]

Iterate over all the Coordinates in this LineString.

type Item = Coordinate<T>

The type of the elements being iterated over.

type IntoIter = IntoIter<Coordinate<T>, Global>

Which kind of iterator are we turning this into?

impl<T: HasKernel> IsConvex for LineString<T>[src]

impl<T> LineInterpolatePoint<T> for LineString<T> where
    T: CoordFloat + AddAssign + Debug,
    Line<T>: EuclideanLength<T>,
    LineString<T>: EuclideanLength<T>, 
[src]

type Output = Option<Point<T>>

impl<T> LineLocatePoint<T, Point<T>> for LineString<T> where
    T: CoordFloat + AddAssign,
    Line<T>: EuclideanDistance<T, Point<T>> + EuclideanLength<T>,
    LineString<T>: EuclideanLength<T>, 
[src]

type Output = Option<T>

type Rhs = Point<T>

impl<T: CoordNum, NT: CoordNum> MapCoords<T, NT> for LineString<T>[src]

type Output = LineString<NT>

impl<T: CoordNum> MapCoordsInplace<T> for LineString<T>[src]

impl<T> PartialEq<LineString<T>> for LineString<T> where
    T: PartialEq<T> + CoordNum
[src]

impl<T> PointDistance for LineString<T> where
    T: Float + RTreeNum
[src]

impl<T> RTreeObject for LineString<T> where
    T: Float + RTreeNum
[src]

type Envelope = AABB<Point<T>>

The object’s envelope type. Usually, AABB will be the right choice. This type also defines the objects dimensionality. Read more

impl<F: GeoFloat> Relate<F, GeometryCollection<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, Line<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for Point<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for Line<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for Polygon<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for MultiPoint<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for MultiLineString<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for MultiPolygon<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for Rect<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for Triangle<F>[src]

impl<F: GeoFloat> Relate<F, LineString<F>> for GeometryCollection<F>[src]

impl<F: GeoFloat> Relate<F, MultiLineString<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, MultiPoint<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, MultiPolygon<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, Point<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, Polygon<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, Rect<F>> for LineString<F>[src]

impl<F: GeoFloat> Relate<F, Triangle<F>> for LineString<F>[src]

impl<T> RelativeEq<LineString<T>> for LineString<T> where
    T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>, 
[src]

pub fn relative_eq(
    &self,
    other: &LineString<T>,
    epsilon: <LineString<T> as AbsDiffEq<LineString<T>>>::Epsilon,
    max_relative: <LineString<T> as AbsDiffEq<LineString<T>>>::Epsilon
) -> bool
[src]

Equality assertion within a relative limit.

Examples

use geo_types::LineString;

let mut coords_a = vec![(0., 0.), (5., 0.), (7., 9.)];
let a: LineString<f32> = coords_a.into_iter().collect();

let mut coords_b = vec![(0., 0.), (5., 0.), (7.001, 9.)];
let b: LineString<f32> = coords_b.into_iter().collect();

approx::assert_relative_eq!(a, b, max_relative=0.1)

impl<T> Rotate<T> for LineString<T> where
    T: GeoFloat
[src]

fn rotate(&self, angle: T) -> Self[src]

Rotate the LineString about its centroid by the given number of degrees

impl<T> Simplify<T, T> for LineString<T> where
    T: GeoFloat
[src]

impl<T> SimplifyIdx<T, T> for LineString<T> where
    T: GeoFloat
[src]

impl<T> SimplifyVW<T, T> for LineString<T> where
    T: CoordFloat
[src]

impl<T> SimplifyVWPreserve<T, T> for LineString<T> where
    T: CoordFloat + RTreeNum
[src]

impl<T> SimplifyVwIdx<T, T> for LineString<T> where
    T: CoordFloat
[src]

impl<T> StructuralEq for LineString<T> where
    T: CoordNum
[src]

impl<T> StructuralPartialEq for LineString<T> where
    T: CoordNum
[src]

impl<T> TryFrom<Geometry<T>> for LineString<T> where
    T: CoordNum
[src]

Convert a Geometry enum into its inner type.

Fails if the enum case does not match the type you are trying to convert it to.

type Error = Error

The type returned in the event of a conversion error.

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for LineString<T>[src]

type Output = LineString<NT>

impl<T> VincentyLength<T, LineString<T>> for LineString<T> where
    T: CoordFloat + FromPrimitive
[src]

impl<T, K> Winding for LineString<T> where
    T: HasKernel<Ker = K>,
    K: Kernel<T>, 
[src]

type Scalar = T

fn points_cw(&self) -> Points<'_, Self::Scalar>

Notable traits for Points<'a, T>

impl<'a, T> Iterator for Points<'a, T> where
    T: CoordNum
type Item = Point<T>;
[src]

Iterate over the points in a clockwise order

The Linestring isn’t changed, and the points are returned either in order, or in reverse order, so that the resultant order makes it appear clockwise

fn points_ccw(&self) -> Points<'_, Self::Scalar>

Notable traits for Points<'a, T>

impl<'a, T> Iterator for Points<'a, T> where
    T: CoordNum
type Item = Point<T>;
[src]

Iterate over the points in a counter-clockwise order

The Linestring isn’t changed, and the points are returned either in order, or in reverse order, so that the resultant order makes it appear counter-clockwise

fn make_cw_winding(&mut self)[src]

Change this line’s points so they are in clockwise winding order

fn make_ccw_winding(&mut self)[src]

Change this line’s points so they are in counterclockwise winding order

Auto Trait Implementations

impl<T> RefUnwindSafe for LineString<T> where
    T: RefUnwindSafe

impl<T> Send for LineString<T> where
    T: Send

impl<T> Sync for LineString<T> where
    T: Sync

impl<T> Unpin for LineString<T> where
    T: Unpin

impl<T> UnwindSafe for LineString<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<'a, T, G> Extremes<'a, T> for G where
    T: CoordNum,
    G: CoordsIter<'a, Scalar = T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, G> RotatePoint<T> for G where
    T: CoordFloat,
    G: MapCoords<T, T, Output = G>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, G> Translate<T> for G where
    T: CoordNum,
    G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.