GenericPolygon

Struct GenericPolygon 

Source
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 Outer rings (p12/34)

§geo-types

shapefile’s Polygons can be converted to geo-types’s MultiPolygon<f64>, but not geo-types’s Polygon as they only allow polygons with one outer ring.

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>

Source

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>

Source

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>

Source

pub fn bbox(&self) -> &GenericBBox<PointType>

Returns the bounding box associated to the polygon

Source

pub fn rings(&self) -> &[PolygonRing<PointType>]

Returns the rings of the polygon

Source

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);
Source

pub fn into_inner(self) -> Vec<PolygonRing<PointType>>

Consumes the shape and returns the rings

Source

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>

Source§

fn clone(&self) -> GenericPolygon<PointType>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<PointType: Debug> Debug for GenericPolygon<PointType>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<GenericPolygon<Point>> for Shape

Source§

fn from(concrete: Polygon) -> Self

Converts to this type from the input type.
Source§

impl From<GenericPolygon<PointM>> for Shape

Source§

fn from(concrete: PolygonM) -> Self

Converts to this type from the input type.
Source§

impl<PointType> From<GenericPolygon<PointType>> for MultiPolygon<f64>
where PointType: ShrinkablePoint + GrowablePoint + Copy, Coordinate<f64>: From<PointType>,

Available on crate feature geo-types only.
Source§

fn from(p: GenericPolygon<PointType>) -> Self

Converts to this type from the input type.
Source§

impl From<GenericPolygon<PointZ>> for Shape

Source§

fn from(concrete: PolygonZ) -> Self

Converts to this type from the input type.
Source§

impl<PointType: HasXY> From<GenericPolyline<PointType>> for GenericPolygon<PointType>

Source§

fn from(polyline: GenericPolyline<PointType>) -> Self

Converts to this type from the input type.
Source§

impl<PointType> From<MultiPolygon> for GenericPolygon<PointType>

Available on crate feature geo-types only.
Source§

fn from(multi_polygon: MultiPolygon<f64>) -> Self

Converts to this type from the input type.
Source§

impl<PointType> From<Polygon> for GenericPolygon<PointType>

Available on crate feature geo-types only.
Source§

fn from(polygon: Polygon<f64>) -> Self

Converts to this type from the input type.
Source§

impl<PointType: PartialEq> PartialEq for GenericPolygon<PointType>

Source§

fn eq(&self, other: &GenericPolygon<PointType>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<PointType> StructuralPartialEq for GenericPolygon<PointType>

Auto Trait Implementations§

§

impl<PointType> Freeze for GenericPolygon<PointType>
where PointType: Freeze,

§

impl<PointType> RefUnwindSafe for GenericPolygon<PointType>
where PointType: RefUnwindSafe,

§

impl<PointType> Send for GenericPolygon<PointType>
where PointType: Send,

§

impl<PointType> Sync for GenericPolygon<PointType>
where PointType: Sync,

§

impl<PointType> Unpin for GenericPolygon<PointType>
where PointType: Unpin,

§

impl<PointType> UnwindSafe for GenericPolygon<PointType>
where PointType: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<S> ReadableShape for S

Source§

fn read_from<T>(source: &mut T, record_size: i32) -> Result<S, Error>
where T: Read,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.