pub struct LineString<T = f64>(pub Vec<Coord<T>>)
where
T: CoordNum;geo-types only.Expand description
An ordered collection of Coords, representing a path between locations.
To be valid, a LineString must be empty, or have two or more coords.
§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 = vec![[0., 0.], [10., 0.]].into();Or by collecting from a Coord 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 Coords 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 Coords 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<Coord<T>>Implementations§
Source§impl<T> LineString<T>where
T: CoordNum,
impl<T> LineString<T>where
T: CoordNum,
Sourcepub fn new(value: Vec<Coord<T>>) -> LineString<T>
pub fn new(value: Vec<Coord<T>>) -> LineString<T>
Returns a LineString with the given coordinates
Sourcepub fn empty() -> LineString<T>
pub fn empty() -> LineString<T>
Returns an empty LineString
Sourcepub fn points_iter(&self) -> PointsIter<'_, T>
👎Deprecated: Use points() instead
pub fn points_iter(&self) -> PointsIter<'_, T>
Return an iterator yielding the coordinates of a LineString as Points
Sourcepub fn points(&self) -> PointsIter<'_, T>
pub fn points(&self) -> PointsIter<'_, T>
Return an iterator yielding the coordinates of a LineString as Points
Sourcepub fn coords(&self) -> impl DoubleEndedIterator
pub fn coords(&self) -> impl DoubleEndedIterator
Return an iterator yielding the members of a LineString as Coords
Sourcepub fn coords_mut(&mut self) -> impl DoubleEndedIterator
pub fn coords_mut(&mut self) -> impl DoubleEndedIterator
Return an iterator yielding the coordinates of a LineString as mutable Coords
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<Coord<T>>
pub fn into_inner(self) -> Vec<Coord<T>>
Return the coordinates of a LineString as a Vec of Coords
Sourcepub fn lines(&self) -> impl ExactSizeIterator
pub fn lines(&self) -> impl ExactSizeIterator
Return an iterator yielding one Line for each line segment
in the LineString.
§Examples
use geo_types::{wkt, Line, LineString};
let line_string = wkt!(LINESTRING(0 0,5 0,7 9));
let mut lines = line_string.lines();
assert_eq!(
Some(Line::new((0, 0), (5, 0))),
lines.next()
);
assert_eq!(
Some(Line::new((5, 0), (7, 9))),
lines.next()
);
assert!(lines.next().is_none());Sourcepub fn rev_lines(&self) -> impl ExactSizeIterator
pub fn rev_lines(&self) -> impl ExactSizeIterator
Return an iterator yielding one Line for each line segment in the LineString,
starting from the end point of the LineString, working towards the start.
Note: This is like Self::lines, but the sequence and the orientation of
segments are reversed.
§Examples
use geo_types::{wkt, Line, LineString};
let line_string = wkt!(LINESTRING(0 0,5 0,7 9));
let mut lines = line_string.rev_lines();
assert_eq!(
Some(Line::new((7, 9), (5, 0))),
lines.next()
);
assert_eq!(
Some(Line::new((5, 0), (0, 0))),
lines.next()
);
assert!(lines.next().is_none());Sourcepub fn triangles(&self) -> impl ExactSizeIterator
pub fn triangles(&self) -> impl ExactSizeIterator
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 Coord, and
the value of the first Coord does not equal the value of the last Coord, then a
new Coord is added to the end with the value of the first Coord.
Sourcepub fn num_coords(&self) -> usize
👎Deprecated: Use geo::CoordsIter::coords_count instead
pub fn num_coords(&self) -> usize
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§
Source§impl<T> Clone for LineString<T>
impl<T> Clone for LineString<T>
Source§fn clone(&self) -> LineString<T>
fn clone(&self) -> LineString<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for LineString<T>where
T: CoordNum,
impl<T> Debug for LineString<T>where
T: CoordNum,
Source§impl<T> From<&Line<T>> for LineString<T>where
T: CoordNum,
impl<T> From<&Line<T>> for LineString<T>where
T: CoordNum,
Source§fn from(line: &Line<T>) -> LineString<T>
fn from(line: &Line<T>) -> LineString<T>
Source§impl<T> From<Line<T>> for LineString<T>where
T: CoordNum,
impl<T> From<Line<T>> for LineString<T>where
T: CoordNum,
Source§fn from(line: Line<T>) -> LineString<T>
fn from(line: Line<T>) -> LineString<T>
Source§impl<T> From<LineString<T>> for Geometry<T>where
T: CoordNum,
impl<T> From<LineString<T>> for Geometry<T>where
T: CoordNum,
Source§fn from(x: LineString<T>) -> Geometry<T>
fn from(x: LineString<T>) -> Geometry<T>
Source§impl<T> From<LineString<T>> for LineString<T>where
T: CoordNum,
impl<T> From<LineString<T>> for LineString<T>where
T: CoordNum,
Source§fn from(line_string: LineString<T>) -> LineString<T>
fn from(line_string: LineString<T>) -> LineString<T>
Convert from a WKT LINESTRING to a geo_types::LineString
Source§impl<T, IC> From<Vec<IC>> for LineString<T>
Turn a Vec of Point-like objects into a LineString.
impl<T, IC> From<Vec<IC>> for LineString<T>
Turn a Vec of Point-like objects into a LineString.
Source§fn from(v: Vec<IC>) -> LineString<T>
fn from(v: Vec<IC>) -> LineString<T>
Source§impl<T, IC> FromIterator<IC> for LineString<T>
Turn an iterator of Point-like objects into a LineString.
impl<T, IC> FromIterator<IC> for LineString<T>
Turn an iterator of Point-like objects into a LineString.
Source§fn from_iter<I>(iter: I) -> LineString<T>where
I: IntoIterator<Item = IC>,
fn from_iter<I>(iter: I) -> LineString<T>where
I: IntoIterator<Item = IC>,
Source§impl<'a, T> GeometryTrait for &'a LineString<T>where
T: CoordNum + 'a,
impl<'a, T> GeometryTrait for &'a LineString<T>where
T: CoordNum + 'a,
Source§type PointType<'b> = Point<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type PointType<'b> = Point<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type LineStringType<'b> = LineString<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type LineStringType<'b> = LineString<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type PolygonType<'b> = Polygon<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type PolygonType<'b> = Polygon<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type MultiPointType<'b> = MultiPoint<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type MultiPointType<'b> = MultiPoint<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type MultiLineStringType<'b> = MultiLineString<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type MultiPolygonType<'b> = MultiPolygon<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type GeometryCollectionType<'b> = GeometryCollection<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type RectType<'b> = Rect<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type RectType<'b> = Rect<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type TriangleType<'b> = Triangle<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type TriangleType<'b> = Triangle<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§type LineType<'b> = Line<<&'a LineString<T> as GeometryTrait>::T>
where
&'a LineString<T>: 'b
type LineType<'b> = Line<<&'a LineString<T> as GeometryTrait>::T> where &'a LineString<T>: 'b
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
Source§fn as_type(
&self,
) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
fn as_type( &self, ) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<T> GeometryTrait for LineString<T>where
T: CoordNum,
impl<T> GeometryTrait for LineString<T>where
T: CoordNum,
Source§type PointType<'b> = Point<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type PointType<'b> = Point<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type LineStringType<'b> = LineString<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type LineStringType<'b> = LineString<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type PolygonType<'b> = Polygon<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type PolygonType<'b> = Polygon<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type MultiPointType<'b> = MultiPoint<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type MultiPointType<'b> = MultiPoint<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type MultiLineStringType<'b> = MultiLineString<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type MultiPolygonType<'b> = MultiPolygon<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type GeometryCollectionType<'b> = GeometryCollection<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type RectType<'b> = Rect<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type RectType<'b> = Rect<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type TriangleType<'b> = Triangle<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type TriangleType<'b> = Triangle<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§type LineType<'b> = Line<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'b
type LineType<'b> = Line<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'b
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
Source§fn as_type(
&self,
) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
fn as_type( &self, ) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<T> Hash for LineString<T>
impl<T> Hash for LineString<T>
Source§impl<'a, T> IntoIterator for &'a LineString<T>where
T: CoordNum,
impl<'a, T> IntoIterator for &'a LineString<T>where
T: CoordNum,
Source§impl<'a, T> IntoIterator for &'a mut LineString<T>where
T: CoordNum,
Mutably iterate over all the Coords in this LineString
impl<'a, T> IntoIterator for &'a mut LineString<T>where
T: CoordNum,
Mutably iterate over all the Coords in this LineString
Source§impl<T> IntoIterator for LineString<T>where
T: CoordNum,
Iterate over all the Coords in this LineString.
impl<T> IntoIterator for LineString<T>where
T: CoordNum,
Iterate over all the Coords in this LineString.
Source§impl<T> LineStringTrait for &LineString<T>where
T: CoordNum,
impl<T> LineStringTrait for &LineString<T>where
T: CoordNum,
Source§type CoordType<'b> = Coord<<&LineString<T> as GeometryTrait>::T>
where
&LineString<T>: 'b
type CoordType<'b> = Coord<<&LineString<T> as GeometryTrait>::T> where &LineString<T>: 'b
Source§fn num_coords(&self) -> usize
fn num_coords(&self) -> usize
Source§unsafe fn coord_unchecked(
&self,
i: usize,
) -> <&LineString<T> as LineStringTrait>::CoordType<'_>
unsafe fn coord_unchecked( &self, i: usize, ) -> <&LineString<T> as LineStringTrait>::CoordType<'_>
Source§fn coords(&self) -> impl DoubleEndedIterator + ExactSizeIterator
fn coords(&self) -> impl DoubleEndedIterator + ExactSizeIterator
Source§impl<T> LineStringTrait for LineString<T>where
T: CoordNum,
impl<T> LineStringTrait for LineString<T>where
T: CoordNum,
Source§type CoordType<'a> = Coord<<LineString<T> as GeometryTrait>::T>
where
LineString<T>: 'a
type CoordType<'a> = Coord<<LineString<T> as GeometryTrait>::T> where LineString<T>: 'a
Source§fn num_coords(&self) -> usize
fn num_coords(&self) -> usize
Source§unsafe fn coord_unchecked(
&self,
i: usize,
) -> <LineString<T> as LineStringTrait>::CoordType<'_>
unsafe fn coord_unchecked( &self, i: usize, ) -> <LineString<T> as LineStringTrait>::CoordType<'_>
Source§fn coords(&self) -> impl DoubleEndedIterator + ExactSizeIterator
fn coords(&self) -> impl DoubleEndedIterator + ExactSizeIterator
Source§impl<T> PartialEq for LineString<T>
impl<T> PartialEq for LineString<T>
Source§impl<T> ToWkt<T> for LineString<T>
§Examples
use geo_types::{line_string, LineString};
use wkt::ToWkt;
let line_string: LineString<f64> = line_string![(x: 1., y: 2.), (x: 3., y: 4.), (x: 5., y: 6.)];
assert_eq!(line_string.wkt_string(), "LINESTRING(1 2,3 4,5 6)");
impl<T> ToWkt<T> for LineString<T>
§Examples
use geo_types::{line_string, LineString};
use wkt::ToWkt;
let line_string: LineString<f64> = line_string![(x: 1., y: 2.), (x: 3., y: 4.), (x: 5., y: 6.)];
assert_eq!(line_string.wkt_string(), "LINESTRING(1 2,3 4,5 6)");Source§impl<T> TryFrom<Geometry<T>> for LineString<T>where
T: CoordNum,
Convert a Geometry enum into its inner type.
impl<T> TryFrom<Geometry<T>> for LineString<T>where
T: CoordNum,
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.
Source§impl<T> TryFrom<Wkt<T>> for LineString<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
impl<T> TryFrom<Wkt<T>> for LineString<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
Source§impl<T> TryFromWkt<T> for LineString<T>
impl<T> TryFromWkt<T> for LineString<T>
type Error = Error
Source§fn try_from_wkt_str(
wkt_str: &str,
) -> Result<LineString<T>, <LineString<T> as TryFromWkt<T>>::Error>
fn try_from_wkt_str( wkt_str: &str, ) -> Result<LineString<T>, <LineString<T> as TryFromWkt<T>>::Error>
Source§fn try_from_wkt_reader(
wkt_reader: impl Read,
) -> Result<LineString<T>, <LineString<T> as TryFromWkt<T>>::Error>
fn try_from_wkt_reader( wkt_reader: impl Read, ) -> Result<LineString<T>, <LineString<T> as TryFromWkt<T>>::Error>
impl<T> Eq for LineString<T>
impl<T> StructuralPartialEq for LineString<T>where
T: CoordNum,
Auto Trait Implementations§
impl<T> Freeze for LineString<T>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, G> ToGeoGeometry<T> for Gwhere
T: CoordNum,
G: GeometryTrait<T = T>,
impl<T, G> ToGeoGeometry<T> for Gwhere
T: CoordNum,
G: GeometryTrait<T = T>,
Source§impl<T, G> ToGeoLineString<T> for Gwhere
T: CoordNum,
G: LineStringTrait<T = T>,
impl<T, G> ToGeoLineString<T> for Gwhere
T: CoordNum,
G: LineStringTrait<T = T>,
Source§fn to_line_string(&self) -> LineString<T>
fn to_line_string(&self) -> LineString<T>
LineString.