Struct geo_types::LineString [−][src]
pub struct LineString<T>(pub Vec<Coordinate<T>>)
where
T: CoordNum;Expand description
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());
}Tuple Fields
0: Vec<Coordinate<T>>Implementations
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>;
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>;
impl<'a, T: CoordNum> Iterator for PointsIter<'a, T> type Item = Point<T>;Return an iterator yielding the coordinates of a LineString as Points
Return the coordinates of a LineString as a Vec of Points
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());An iterator which yields the coordinates of a LineString as Triangles
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.
👎 Deprecated: Use geo::algorithm::coords_iter::CoordsIter::coords_count instead
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());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
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)type Epsilon = T
type Epsilon = T
Used for specifying relative comparisons.
The default tolerance to use when testing values that are close together. Read more
The inverse of AbsDiffEq::abs_diff_eq.
Performs the conversion.
Turn a Vec of Point-like objects into a LineString.
Turn an iterator of Point-like objects into a LineString.
Creates a value from an iterator. Read more
type Output = Coordinate<T>
type Output = Coordinate<T>
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
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>>
type IntoIter = IntoIter<Coordinate<T>>
Which kind of iterator are we turning this into?
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?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
impl<T> RelativeEq<LineString<T>> for LineString<T> where
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq,
impl<T> RelativeEq<LineString<T>> for LineString<T> where
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq,
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)The default relative tolerance for testing values that are far-apart. Read more
The inverse of RelativeEq::relative_eq.
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.
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
Mutably borrows from an owned value. Read more
