Struct geo_types::LineString
source · [−]pub struct LineString<T: CoordNum>(pub Vec<Coordinate<T>>);Expand description
An ordered collection of two or more Coordinates, representing a
path between locations.
Semantics
- A
LineStringis closed if it is empty, or if the first and last coordinates are the same. - The boundary of a
LineStringis either:- empty if it is closed (see 1) or
- contains the start and end coordinates.
- The interior is the (infinite) set of all coordinates along the
LineString, not including the boundary. - A
LineStringis simple if it does not intersect except optionally at the first and last coordinates (in which case it is also closed, see 1). - A simple and closed
LineStringis aLinearRingas defined in the OGC-SFA (but is not defined as a separate type in this crate).
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 its
validity is not enforced, and operations and
predicates are undefined on invalid LineStrings.
Examples
Creation
Create a LineString by calling it directly:
use geo_types::{coord, LineString};
let line_string = LineString::new(vec![
coord! { x: 0., y: 0. },
coord! { 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.),
];By converting from 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 by collecting from a Coordinate iterator
use geo_types::{coord, LineString};
let mut coords_iter =
vec![coord! { x: 0., y: 0. }, coord! { x: 10., y: 0. }].into_iter();
let line_string: LineString<f32> = coords_iter.collect();Iteration
LineString provides five iterators: coords, coords_mut, points, lines, and triangles:
use geo_types::{coord, LineString};
let line_string = LineString::new(vec![
coord! { x: 0., y: 0. },
coord! { x: 10., y: 0. },
]);
line_string.coords().for_each(|coord| println!("{:?}", coord));
for point in line_string.points() {
println!("Point x = {}, y = {}", point.x(), point.y());
}Note that its IntoIterator impl yields Coordinates when looping:
use geo_types::{coord, LineString};
let line_string = LineString::new(vec![
coord! { x: 0., y: 0. },
coord! { x: 10., y: 0. },
]);
for coord in &line_string {
println!("Coordinate x = {}, y = {}", coord.x, coord.y);
}
for coord in line_string {
println!("Coordinate x = {}, y = {}", coord.x, coord.y);
}
Decomposition
You can decompose a LineString into a Vec of Coordinates or Points:
use geo_types::{coord, LineString, Point};
let line_string = LineString::new(vec![
coord! { x: 0., y: 0. },
coord! { x: 10., y: 0. },
]);
let coordinate_vec = line_string.clone().into_inner();
let point_vec = line_string.clone().into_points();
Tuple Fields
0: Vec<Coordinate<T>>Implementations
sourceimpl<T: CoordNum> LineString<T>
impl<T: CoordNum> LineString<T>
sourcepub fn new(value: Vec<Coordinate<T>>) -> Self
pub fn new(value: Vec<Coordinate<T>>) -> Self
Instantiate Self from the raw content value
sourcepub 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>;
👎 Deprecated: Use points() instead
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>;
Use points() instead
Return an iterator yielding the coordinates of a LineString as Points
sourcepub fn points(&self) -> PointsIter<'_, T>ⓘNotable traits for PointsIter<'a, T>impl<'a, T: CoordNum> Iterator for PointsIter<'a, T> type Item = Point<T>;
pub fn points(&self) -> PointsIter<'_, T>ⓘNotable traits for PointsIter<'a, T>impl<'a, T: CoordNum> Iterator for PointsIter<'a, T> type Item = Point<T>;
Return an iterator yielding the coordinates of a LineString as Points
sourcepub fn coords(&self) -> impl Iterator<Item = &Coordinate<T>>
pub fn coords(&self) -> impl Iterator<Item = &Coordinate<T>>
Return an iterator yielding the members of a LineString as Coordinates
sourcepub fn coords_mut(&mut self) -> impl Iterator<Item = &mut Coordinate<T>>
pub fn coords_mut(&mut self) -> impl Iterator<Item = &mut Coordinate<T>>
Return an iterator yielding the coordinates of a LineString as mutable Coordinates
sourcepub fn into_points(self) -> Vec<Point<T>>
pub fn into_points(self) -> Vec<Point<T>>
Return the coordinates of a LineString as a Vec of Points
sourcepub fn into_inner(self) -> Vec<Coordinate<T>>
pub fn into_inner(self) -> Vec<Coordinate<T>>
Return the coordinates of a LineString as a Vec of Coordinates
sourcepub fn lines(&self) -> impl ExactSizeIterator + Iterator<Item = Line<T>> + '_
pub fn lines(&self) -> impl ExactSizeIterator + Iterator<Item = Line<T>> + '_
Return an iterator yielding one Line for each line segment
in the LineString.
Examples
use geo_types::{coord, 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(
coord! { x: 0., y: 0. },
coord! { x: 5., y: 0. }
)),
lines.next()
);
assert_eq!(
Some(Line::new(
coord! { x: 5., y: 0. },
coord! { x: 7., y: 9. }
)),
lines.next()
);
assert!(lines.next().is_none());sourcepub fn triangles(
&self
) -> impl ExactSizeIterator + Iterator<Item = Triangle<T>> + '_
pub fn triangles(
&self
) -> impl ExactSizeIterator + Iterator<Item = Triangle<T>> + '_
An iterator which yields the coordinates of a LineString as Triangles
sourcepub fn close(&mut self)
pub fn close(&mut self)
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.
sourcepub fn num_coords(&self) -> usize
👎 Deprecated: Use geo::CoordsIter::coords_count instead
pub fn num_coords(&self) -> usize
Use geo::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());sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
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 elsewhere; And there
seems to be no reason to maintain the separate behavior for LineStrings used in
non-LinearRing contexts.
Trait Implementations
sourceimpl<T: Clone + CoordNum> Clone for LineString<T>
impl<T: Clone + CoordNum> Clone for LineString<T>
sourcefn clone(&self) -> LineString<T>
fn clone(&self) -> LineString<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<T: Debug + CoordNum> Debug for LineString<T>
impl<T: Debug + CoordNum> Debug for LineString<T>
sourceimpl<T: CoordNum> From<Line<T>> for LineString<T>
impl<T: CoordNum> From<Line<T>> for LineString<T>
sourceimpl<T: CoordNum> From<LineString<T>> for Geometry<T>
impl<T: CoordNum> From<LineString<T>> for Geometry<T>
sourcefn from(x: LineString<T>) -> Self
fn from(x: LineString<T>) -> Self
Converts to this type from the input type.
sourceimpl<T: CoordNum, IC: Into<Coordinate<T>>> From<Vec<IC, Global>> for LineString<T>
impl<T: CoordNum, IC: Into<Coordinate<T>>> From<Vec<IC, Global>> for LineString<T>
Turn a Vec of Point-like objects into a LineString.
sourceimpl<T: CoordNum, IC: Into<Coordinate<T>>> FromIterator<IC> for LineString<T>
impl<T: CoordNum, IC: Into<Coordinate<T>>> FromIterator<IC> for LineString<T>
Turn an iterator of Point-like objects into a LineString.
sourcefn from_iter<I: IntoIterator<Item = IC>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = IC>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<T: Hash + CoordNum> Hash for LineString<T>
impl<T: Hash + CoordNum> Hash for LineString<T>
sourceimpl<T: CoordNum> Index<usize> for LineString<T>
impl<T: CoordNum> Index<usize> for LineString<T>
type Output = Coordinate<T>
type Output = Coordinate<T>
The returned type after indexing.
sourcefn index(&self, index: usize) -> &Coordinate<T>
fn index(&self, index: usize) -> &Coordinate<T>
Performs the indexing (container[index]) operation. Read more
sourceimpl<T: CoordNum> IndexMut<usize> for LineString<T>
impl<T: CoordNum> IndexMut<usize> for LineString<T>
sourcefn index_mut(&mut self, index: usize) -> &mut Coordinate<T>
fn index_mut(&mut self, index: usize) -> &mut Coordinate<T>
Performs the mutable indexing (container[index]) operation. Read more
sourceimpl<T: CoordNum> IntoIterator for LineString<T>
impl<T: CoordNum> IntoIterator for LineString<T>
Iterate over all the Coordinates in this LineString.
type Item = Coordinate<T>
type Item = Coordinate<T>
The type of the elements being iterated over.
type IntoIter = IntoIter<Coordinate<T>, Global>
type IntoIter = IntoIter<Coordinate<T>, Global>
Which kind of iterator are we turning this into?
sourceimpl<'a, T: CoordNum> IntoIterator for &'a LineString<T>
impl<'a, T: CoordNum> IntoIterator for &'a LineString<T>
sourceimpl<'a, T: CoordNum> IntoIterator for &'a mut LineString<T>
impl<'a, T: CoordNum> IntoIterator for &'a mut LineString<T>
Mutably iterate over all the Coordinates in this LineString
type Item = &'a mut Coordinate<T>
type Item = &'a mut Coordinate<T>
The type of the elements being iterated over.
type IntoIter = IterMut<'a, Coordinate<T>>
type IntoIter = IterMut<'a, Coordinate<T>>
Which kind of iterator are we turning this into?
sourcefn into_iter(self) -> IterMut<'a, Coordinate<T>>
fn into_iter(self) -> IterMut<'a, Coordinate<T>>
Creates an iterator from a value. Read more
sourceimpl<T: PartialEq + CoordNum> PartialEq<LineString<T>> for LineString<T>
impl<T: PartialEq + CoordNum> PartialEq<LineString<T>> for LineString<T>
sourcefn eq(&self, other: &LineString<T>) -> bool
fn eq(&self, other: &LineString<T>) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &LineString<T>) -> bool
fn ne(&self, other: &LineString<T>) -> bool
This method tests for !=.
sourceimpl<T: CoordNum> TryFrom<Geometry<T>> for LineString<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for LineString<T>
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.
impl<T: Eq + CoordNum> Eq for LineString<T>
impl<T: CoordNum> StructuralEq for LineString<T>
impl<T: CoordNum> StructuralPartialEq for LineString<T>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
