logo

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

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

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)

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.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

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

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

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.

The type of the elements being iterated over.

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.

The type of the elements being iterated over.

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 !=.

Returns the squared euclidean distance of an object to a point.

Returns true if a point is contained within this object. Read more

Returns the squared distance to this object or None if the distance is larger than a given maximum value. Read more

The object’s envelope type. Usually, AABB will be the right choice. This type also defines the objects dimensionality. Read more

Returns the object’s envelope. Read more

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.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.