Struct geo::LineString [−][src]
pub struct LineString<T>(pub Vec<Coordinate<T>, Global>)
where
T: CoordNum;
Expand description
An ordered collection of two or more Coordinate
s, 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 collect
ing 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 Point
s:
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>, Global>
Implementations
Return an iterator yielding the coordinates of a LineString
as Point
s
Return the coordinates of a LineString
as a Vec
of Point
s
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 Triangle
s
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
impl<T> AbsDiffEq<LineString<T>> for LineString<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
impl<T> AbsDiffEq<LineString<T>> for LineString<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
pub fn abs_diff_eq(
&self,
other: &LineString<T>,
epsilon: <LineString<T> as AbsDiffEq<LineString<T>>>::Epsilon
) -> bool
pub fn abs_diff_eq(
&self,
other: &LineString<T>,
epsilon: <LineString<T> as AbsDiffEq<LineString<T>>>::Epsilon
) -> bool
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
.
Find the closest point between self
and p
.
type Scalar = T
type Scalar = T
fn calculate_coordinate_position(
&self,
coord: &Coordinate<T>,
is_inside: &mut bool,
boundary_count: &mut usize
)
Return the number of coordinates in the LineString
.
type Iter = Copied<Iter<'a, Coordinate<T>>>
type ExteriorIter = Self::Iter
type Scalar = T
Iterate over all exterior and (if any) interior coordinates of a geometry. Read more
Iterate over all exterior coordinates of a geometry. Read more
impl<T> EuclideanDistance<T, Line<T>> for LineString<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
impl<T> EuclideanDistance<T, Line<T>> for LineString<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
LineString to Line
Returns the distance between two geometries Read more
Minimum distance from a Point to a LineString
impl<T> EuclideanDistance<T, LineString<T>> for Line<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
impl<T> EuclideanDistance<T, LineString<T>> for Line<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
Line to LineString
Returns the distance between two geometries Read more
impl<T> EuclideanDistance<T, LineString<T>> for LineString<T> where
T: GeoFloat + Signed + RTreeNum,
impl<T> EuclideanDistance<T, LineString<T>> for LineString<T> where
T: GeoFloat + Signed + RTreeNum,
LineString-LineString distance
Returns the distance between two geometries Read more
impl<T> EuclideanDistance<T, LineString<T>> for Polygon<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
impl<T> EuclideanDistance<T, LineString<T>> for Polygon<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
Polygon to LineString distance
Returns the distance between two geometries Read more
Minimum distance from a LineString to a Point
impl<T> EuclideanDistance<T, Polygon<T>> for LineString<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
impl<T> EuclideanDistance<T, Polygon<T>> for LineString<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
LineString to Polygon
Returns the distance between two geometries Read more
Calculation of the length of a Line Read more
Determine the similarity between two LineStrings
using the Frechet distance. Read more
Performs the conversion.
Performs the conversion.
impl<T, IC> From<Vec<IC, Global>> for LineString<T> where
T: CoordNum,
IC: Into<Coordinate<T>>,
impl<T, IC> From<Vec<IC, Global>> for LineString<T> where
T: CoordNum,
IC: Into<Coordinate<T>>,
Turn a Vec
of Point
-like objects into a LineString
.
Performs the conversion.
Turn an iterator of Point
-like objects into a LineString
.
Creates a value from an iterator. Read more
Determine the length of a geometry on an ellipsoidal model of the earth. Read more
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());
Some geometries, like a MultiPoint
, can have zero coordinates - we call these empty
. Read more
The dimensions of some geometries are fixed, e.g. a Point always has 0 dimensions. However
for others, the dimensionality depends on the specific geometry instance - for example
typical Rect
s are 2-dimensional, but it’s possible to create degenerate Rect
s which
have either 1 or 0 dimensions. Read more
impl<T> HaversineLength<T, LineString<T>> for LineString<T> where
T: CoordFloat + FromPrimitive,
impl<T> HaversineLength<T, LineString<T>> for LineString<T> where
T: CoordFloat + FromPrimitive,
Determine the length of a geometry using the haversine formula. 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
impl<T> Intersects<LineString<T>> for Coordinate<T> where
LineString<T>: Intersects<Coordinate<T>>,
T: CoordNum,
impl<T> Intersects<LineString<T>> for Coordinate<T> where
LineString<T>: Intersects<Coordinate<T>>,
T: CoordNum,
impl<T> Intersects<LineString<T>> for Line<T> where
LineString<T>: Intersects<Line<T>>,
T: CoordNum,
impl<T> Intersects<LineString<T>> for Line<T> where
LineString<T>: Intersects<Line<T>>,
T: CoordNum,
impl<T> Intersects<LineString<T>> for Polygon<T> where
LineString<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<LineString<T>> for Polygon<T> where
LineString<T>: Intersects<Polygon<T>>,
T: CoordNum,
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?
Creates an iterator from a value. Read more
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
fn convex_orientation(
&self,
allow_collinear: bool,
specific_orientation: Option<Orientation>
) -> Option<Orientation>
fn convex_orientation(
&self,
allow_collinear: bool,
specific_orientation: Option<Orientation>
) -> Option<Orientation>
Test and get the orientation if the shape is convex.
Tests for strict convexity if allow_collinear
, and
only accepts a specific orientation if provided. Read more
Test if the shape lies on a line.
Test if the shape is convex, and oriented counter-clockwise. Read more
Test if the shape is convex, and oriented clockwise.
Test if the shape is strictly convex.
Test if the shape is strictly convex, and oriented counter-clockwise. Read more
Test if the shape is strictly convex, and oriented clockwise. Read more
impl<T> LineInterpolatePoint<T> for LineString<T> where
T: CoordFloat + AddAssign + Debug,
Line<T>: EuclideanLength<T>,
LineString<T>: EuclideanLength<T>,
impl<T> LineInterpolatePoint<T> for LineString<T> where
T: CoordFloat + AddAssign + Debug,
Line<T>: EuclideanLength<T>,
LineString<T>: EuclideanLength<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>,
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>,
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<T, Epsilon = T> + CoordNum + RelativeEq<T>,
impl<T> RelativeEq<LineString<T>> for LineString<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
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
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
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
.
Returns the simplified representation of a geometry, using the Ramer–Douglas–Peucker algorithm Read more
Returns the simplified indices of a geometry, using the Ramer–Douglas–Peucker algorithm Read more
Returns the simplified representation of a geometry, using the Visvalingam-Whyatt algorithm Read more
Returns the simplified representation of a geometry, using a topology-preserving variant of the Visvalingam-Whyatt algorithm. Read more
Returns the simplified representation of a geometry, using the Visvalingam-Whyatt algorithm Read more
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> VincentyLength<T, LineString<T>> for LineString<T> where
T: CoordFloat + FromPrimitive,
impl<T> VincentyLength<T, LineString<T>> for LineString<T> where
T: CoordFloat + FromPrimitive,
Determine the length of a geometry using Vincenty’s formulae. Read more
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
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
Change this line’s points so they are in clockwise winding order
Change this line’s points so they are in counterclockwise winding order
type Scalar = T
Return the winding order of this object if it
contains at least three distinct coordinates, and
None
otherwise. Read more
fn clone_to_winding_order(&self, winding_order: WindingOrder) -> Self where
Self: Sized + Clone,
fn clone_to_winding_order(&self, winding_order: WindingOrder) -> Self where
Self: Sized + Clone,
Return a clone of this object, but in the specified winding order
Change the winding order so that it is in this 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
Mutably borrows from an owned value. Read more
Rotate a Geometry around an arbitrary point by an angle, given in degrees Read more