pub struct GeometryCollection<T: CoordNum = f64>(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§
Source§impl<T: CoordNum> GeometryCollection<T>
impl<T: CoordNum> GeometryCollection<T>
Sourcepub fn new() -> Self
👎Deprecated: Will be replaced with a parametrized version in upcoming version. Use GeometryCollection::empty() instead
pub fn new() -> Self
Will be replaced with a parametrized version in upcoming version. Use GeometryCollection::empty() instead
Return an empty GeometryCollection
Sourcepub fn new_from(value: Vec<Geometry<T>>) -> Self
pub fn new_from(value: Vec<Geometry<T>>) -> Self
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this GeometryCollection contains zero geometries.
This is a purely structural check: it tests only whether the
underlying collection has no elements. It does not recurse into
the contained geometries, so a collection holding only empty
geometries (for example a single empty LineString) is not
considered empty by this method.
If you need the dimensional notion of emptiness — where a collection
is empty when it has no geometries or all of its geometries are
themselves empty — use geo::HasDimensions::is_empty instead.
§Examples
use geo_types::{GeometryCollection, LineString};
// A collection with no geometries is empty.
let gc = GeometryCollection::<f64>::new_from(vec![]);
assert!(gc.is_empty());
// A collection containing a single (empty) geometry is NOT empty:
// the element is present even though it has no coordinates.
let gc = GeometryCollection::<f64>::new_from(vec![
LineString::<f64>::new(vec![]).into(),
]);
assert!(!gc.is_empty());Trait Implementations§
Source§impl<T: Clone + CoordNum> Clone for GeometryCollection<T>
impl<T: Clone + CoordNum> Clone for GeometryCollection<T>
Source§fn clone(&self) -> GeometryCollection<T>
fn clone(&self) -> GeometryCollection<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: CoordNum> Debug for GeometryCollection<T>
impl<T: CoordNum> Debug for GeometryCollection<T>
Source§impl<T: CoordNum> Default for GeometryCollection<T>
impl<T: CoordNum> Default for GeometryCollection<T>
impl<T: Eq + CoordNum> Eq for GeometryCollection<T>
Source§impl<T: CoordNum, IG: Into<Geometry<T>>> From<IG> for GeometryCollection<T>
DO NOT USE! Deprecated since 0.7.5.
impl<T: CoordNum, IG: Into<Geometry<T>>> From<IG> for GeometryCollection<T>
DO NOT USE! Deprecated since 0.7.5.
Use GeometryCollection::from(vec![geom]) instead.
Source§impl<T: CoordNum, IG: Into<Geometry<T>>> FromIterator<IG> for GeometryCollection<T>
Collect Geometries (or what can be converted to a Geometry) into a GeometryCollection
impl<T: CoordNum, IG: Into<Geometry<T>>> FromIterator<IG> for GeometryCollection<T>
Collect Geometries (or what can be converted to a Geometry) into a GeometryCollection