logo
pub struct GeometryCollection<T: CoordNum>(pub Vec<Geometry<T>>);
Expand description

A collection of Geometry types.

It can be created from a Vec of Geometries, or from an Iterator which yields Geometries.

Looping over this object yields its component Geometry enum members (not the underlying geometry primitives), and it supports iteration and indexing as well as the various MapCoords functions, which are directly applied to the underlying geometry primitives.

Examples

Looping

use std::convert::TryFrom;
use geo_types::{Point, point, Geometry, GeometryCollection};
let p = point!(x: 1.0, y: 1.0);
let pe = Geometry::Point(p);
let gc = GeometryCollection::new_from(vec![pe]);
for geom in gc {
    println!("{:?}", Point::try_from(geom).unwrap().x());
}

Implements iter()

use std::convert::TryFrom;
use geo_types::{Point, point, Geometry, GeometryCollection};
let p = point!(x: 1.0, y: 1.0);
let pe = Geometry::Point(p);
let gc = GeometryCollection::new_from(vec![pe]);
gc.iter().for_each(|geom| println!("{:?}", geom));

Mutable Iteration

use std::convert::TryFrom;
use geo_types::{Point, point, Geometry, GeometryCollection};
let p = point!(x: 1.0, y: 1.0);
let pe = Geometry::Point(p);
let mut gc = GeometryCollection::new_from(vec![pe]);
gc.iter_mut().for_each(|geom| {
   if let Geometry::Point(p) = geom {
       p.set_x(0.2);
   }
});
let updated = gc[0].clone();
assert_eq!(Point::try_from(updated).unwrap().x(), 0.2);

Indexing

use std::convert::TryFrom;
use geo_types::{Point, point, Geometry, GeometryCollection};
let p = point!(x: 1.0, y: 1.0);
let pe = Geometry::Point(p);
let gc = GeometryCollection::new_from(vec![pe]);
println!("{:?}", gc[0]);

Tuple Fields

0: Vec<Geometry<T>>

Implementations

👎 Deprecated:

Will be replaced with a parametrized version in upcoming version. Use GeometryCollection::default() instead

Return an empty GeometryCollection

DO NOT USE! This fn will be renamed to new in the upcoming version. This fn is not marked as deprecated because it would require extensive refactoring of the geo code.

Number of geometries in this GeometryCollection

Is this GeometryCollection empty

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Convert any Geometry (or anything that can be converted to a Geometry) into a GeometryCollection

Converts to this type from the input type.

Collect Geometries (or what can be converted to a Geometry) into a GeometryCollection

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

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

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

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

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.