pub struct GenericPolygon<PointType> { /* private fields */ }Expand description
Generic struct to create Polygon; PolygonM, PolygonZ
Polygons can have multiple parts (or rings)
To create a polygon with only one part use new.
To create a polygon with multiple rings use with_rings.
§Notes
- A Polygon ring is a connected sequence of 4 or more points (this is not checked)
- Polygon’s rings MUST be closed (the first and last points MUST be the same) (p 13/34) (this is done by the constructors if you do not do it yourself)
- The order of rings is not significant (p 13/34)
- A polygon may have multiple
Outerrings (p12/34)
§geo-types
shapefile’s Polygons can be converted to geo-types’s MultiPolygon<f64>,
but not geo-types’s Polygon
geo-types’s Polygon<f64> and MultiPolygon<f64> can be converted to shapefile’s Polygon
let mut polygons = shapefile::read_shapes_as::<_, shapefile::PolygonM>("tests/data/polygonm.shp")?;
let geo_polygon: geo_types::MultiPolygon<f64> = polygons.pop().unwrap().into();
let polygon = shapefile::PolygonZ::from(geo_polygon);Implementations§
Source§impl<PointType> GenericPolygon<PointType>
impl<PointType> GenericPolygon<PointType>
Sourcepub fn new(ring: PolygonRing<PointType>) -> Self
pub fn new(ring: PolygonRing<PointType>) -> Self
Creates a polygon with only one ring
The ring will be closed if it is not (shapefiles requires the first and last point to be equal)
The ring points may be reordered to match their type
(see PolygonRing)
§Examples
use shapefile::{PolygonRing, PointZ, PolygonZ, NO_DATA};
let ring = PolygonRing::Outer(vec![
PointZ::new(0.0, 0.0, 0.0, NO_DATA),
PointZ::new(0.0, 1.0, 0.0, NO_DATA),
PointZ::new(1.0, 1.0, 0.0, NO_DATA),
PointZ::new(1.0, 0.0, 0.0, NO_DATA),
]);
let poly = PolygonZ::new(ring);
assert_eq!(poly.rings()[0].points().first(), poly.rings()[0].points().last());Source§impl<PointType> GenericPolygon<PointType>
impl<PointType> GenericPolygon<PointType>
Sourcepub fn with_rings(rings: Vec<PolygonRing<PointType>>) -> Self
pub fn with_rings(rings: Vec<PolygonRing<PointType>>) -> Self
Creates a polygon with multiple rings
The ring will be closed if it is not (shapefiles requires the first and last point to be equal)
The ring points may be reordered to match their type
(see PolygonRing)
§Example
use shapefile::{PolygonRing, Point, Polygon};
let polygon = Polygon::with_rings(vec![
PolygonRing::Outer(vec![
Point::new(-120.0, 60.0),
Point::new(-120.0, -60.0),
Point::new(120.0, -60.0),
Point::new(120.0, 60.0),
Point::new(-120.0, 60.0),
]),
PolygonRing::Inner(vec![
Point::new(-60.0, 30.0),
Point::new(60.0, 30.0),
Point::new(60.0, -30.0),
Point::new(-60.0, -30.0),
Point::new(-60.0, 30.0),
]),
]);
assert_eq!(polygon.rings().len(), 2);Source§impl<PointType> GenericPolygon<PointType>
impl<PointType> GenericPolygon<PointType>
Sourcepub fn bbox(&self) -> &GenericBBox<PointType>
pub fn bbox(&self) -> &GenericBBox<PointType>
Returns the bounding box associated to the polygon
Sourcepub fn rings(&self) -> &[PolygonRing<PointType>]
pub fn rings(&self) -> &[PolygonRing<PointType>]
Returns the rings of the polygon
Sourcepub fn ring(&self, index: usize) -> Option<&PolygonRing<PointType>>
pub fn ring(&self, index: usize) -> Option<&PolygonRing<PointType>>
Returns the ring as index
§Example
use shapefile::{polygon, NO_DATA};
let polygon = polygon!{
Outer(
(0.0, 0.0, 0.0, NO_DATA),
(0.0, 1.0, 0.0, NO_DATA),
(1.0, 1.0, 0.0, NO_DATA),
(1.0, 0.0, 0.0, NO_DATA),
)
};
assert_eq!( polygon.ring(0).is_some(), true);
assert_eq!(polygon.ring(1), None);Sourcepub fn into_inner(self) -> Vec<PolygonRing<PointType>>
pub fn into_inner(self) -> Vec<PolygonRing<PointType>>
Consumes the shape and returns the rings
Sourcepub fn total_point_count(&self) -> usize
pub fn total_point_count(&self) -> usize
Returns the sum of points of all the rings
Trait Implementations§
Source§impl<PointType: Clone> Clone for GenericPolygon<PointType>
impl<PointType: Clone> Clone for GenericPolygon<PointType>
Source§fn clone(&self) -> GenericPolygon<PointType>
fn clone(&self) -> GenericPolygon<PointType>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<PointType: Debug> Debug for GenericPolygon<PointType>
impl<PointType: Debug> Debug for GenericPolygon<PointType>
Source§impl<PointType> From<GenericPolygon<PointType>> for MultiPolygon<f64>
Available on crate feature geo-types only.
impl<PointType> From<GenericPolygon<PointType>> for MultiPolygon<f64>
geo-types only.Source§fn from(p: GenericPolygon<PointType>) -> Self
fn from(p: GenericPolygon<PointType>) -> Self
Source§impl<PointType: HasXY> From<GenericPolyline<PointType>> for GenericPolygon<PointType>
impl<PointType: HasXY> From<GenericPolyline<PointType>> for GenericPolygon<PointType>
Source§fn from(polyline: GenericPolyline<PointType>) -> Self
fn from(polyline: GenericPolyline<PointType>) -> Self
Source§impl<PointType> From<MultiPolygon> for GenericPolygon<PointType>where
PointType: HasXY + From<Coordinate<f64>> + GrowablePoint + ShrinkablePoint + PartialEq + Copy,
Available on crate feature geo-types only.
impl<PointType> From<MultiPolygon> for GenericPolygon<PointType>where
PointType: HasXY + From<Coordinate<f64>> + GrowablePoint + ShrinkablePoint + PartialEq + Copy,
geo-types only.Source§fn from(multi_polygon: MultiPolygon<f64>) -> Self
fn from(multi_polygon: MultiPolygon<f64>) -> Self
Source§impl<PointType> From<Polygon> for GenericPolygon<PointType>where
PointType: From<Coordinate<f64>> + GrowablePoint + ShrinkablePoint + PartialEq + HasXY + Copy,
Available on crate feature geo-types only.
impl<PointType> From<Polygon> for GenericPolygon<PointType>where
PointType: From<Coordinate<f64>> + GrowablePoint + ShrinkablePoint + PartialEq + HasXY + Copy,
geo-types only.