[][src]Struct geo_types::LineString

pub struct LineString<T>(pub Vec<Coordinate<T>>)
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: CoordNum> LineString<T>[src]

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

Notable traits for PointsIter<'a, T>

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

Return an iterator yielding the coordinates of a LineString as Points

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

Return the coordinates of a LineString as a Vec of Points

pub fn lines<'a>(
    &'a self
) -> impl ExactSizeIterator + Iterator<Item = Line<T>> + 'a
[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<'a>(
    &'a self
) -> impl ExactSizeIterator + Iterator<Item = Triangle<T>> + 'a
[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: Clone> Clone for LineString<T> where
    T: CoordNum
[src]

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

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

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

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

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

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

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

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

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

type Output = Coordinate<T>

The returned type after indexing.

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

impl<T: CoordNum> IntoIterator for LineString<T>[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>>

Which kind of iterator are we turning this into?

impl<'a, T: CoordNum> IntoIterator for &'a mut LineString<T>[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: PartialEq> PartialEq<LineString<T>> for LineString<T> where
    T: CoordNum
[src]

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

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

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

type Error = FailedToConvertError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<T> RefUnwindSafe for LineString<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for LineString<T> where
    T: Send
[src]

impl<T> Sync for LineString<T> where
    T: Sync
[src]

impl<T> Unpin for LineString<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for LineString<T> where
    T: UnwindSafe
[src]

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<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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.