pub struct Polygon { /* private fields */ }Expand description
A polygon with exterior and optional interior rings.
This wraps geo::Polygon and provides additional functionality for
GeoJSON conversion and spatial operations.
§Examples
use spatio_types::geo::Polygon;
use geo::polygon;
let poly = polygon![
(x: -80.0, y: 35.0),
(x: -70.0, y: 35.0),
(x: -70.0, y: 45.0),
(x: -80.0, y: 45.0),
(x: -80.0, y: 35.0),
];
let wrapped = Polygon::from(poly);Implementations§
Source§impl Polygon
impl Polygon
Sourcepub fn new(exterior: LineString<f64>, interiors: Vec<LineString<f64>>) -> Self
pub fn new(exterior: LineString<f64>, interiors: Vec<LineString<f64>>) -> Self
Create a new polygon from an exterior ring and optional interior rings (holes).
§Arguments
exterior- The outer boundary of the polygoninteriors- Optional holes within the polygon
Sourcepub fn from_coords(
exterior: &[(f64, f64)],
interiors: Vec<Vec<(f64, f64)>>,
) -> Self
pub fn from_coords( exterior: &[(f64, f64)], interiors: Vec<Vec<(f64, f64)>>, ) -> Self
Create a new polygon from coordinate arrays without requiring geo::LineString.
This is a convenience method that allows creating polygons from raw coordinates
without needing to import types from the geo crate.
§Arguments
exterior- Coordinates for the outer boundary [(lon, lat), …]interiors- Optional holes within the polygon, each as [(lon, lat), …]
§Examples
use spatio_types::geo::Polygon;
// Create a simple rectangle
let polygon = Polygon::from_coords(
&[
(-80.0, 35.0),
(-70.0, 35.0),
(-70.0, 45.0),
(-80.0, 45.0),
(-80.0, 35.0), // Close the ring
],
vec![],
);
// Create a polygon with a hole
let polygon_with_hole = Polygon::from_coords(
&[
(-80.0, 35.0),
(-70.0, 35.0),
(-70.0, 45.0),
(-80.0, 45.0),
(-80.0, 35.0),
],
vec![
vec![
(-75.0, 38.0),
(-74.0, 38.0),
(-74.0, 40.0),
(-75.0, 40.0),
(-75.0, 38.0),
]
],
);Sourcepub fn exterior(&self) -> &LineString<f64>
pub fn exterior(&self) -> &LineString<f64>
Get a reference to the exterior ring.
Sourcepub fn interiors(&self) -> &[LineString<f64>]
pub fn interiors(&self) -> &[LineString<f64>]
Get references to the interior rings (holes).
Sourcepub fn into_inner(self) -> Polygon<f64>
pub fn into_inner(self) -> Polygon<f64>
Convert into the inner geo::Polygon.
Sourcepub fn contains(&self, point: &Point) -> bool
pub fn contains(&self, point: &Point) -> bool
Check if a point is contained within this polygon.
§Examples
use spatio_types::geo::{Point, Polygon};
use geo::polygon;
let poly = polygon![
(x: -80.0, y: 35.0),
(x: -70.0, y: 35.0),
(x: -70.0, y: 45.0),
(x: -80.0, y: 45.0),
(x: -80.0, y: 35.0),
];
let polygon = Polygon::from(poly);
let point = Point::new(-75.0, 40.0);
assert!(polygon.contains(&point));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Polygon
impl<'de> Deserialize<'de> for Polygon
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Polygon
Auto Trait Implementations§
impl Freeze for Polygon
impl RefUnwindSafe for Polygon
impl Send for Polygon
impl Sync for Polygon
impl Unpin for Polygon
impl UnwindSafe for Polygon
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more