Trait geo::algorithm::interior_point::InteriorPoint
source · [−]pub trait InteriorPoint {
type Output;
fn interior_point(&self) -> Self::Output;
}
Expand description
Calculation of interior points. An interior point is a point that’s guaranteed to intersect a given geometry, and will be strictly on the interior of the geometry if possible, or on the edge if the geometry has zero area. A best effort will additionally be made to locate the point reasonably centrally.
For polygons, this point is located by drawing a line that approximately subdivides the bounding box around the polygon in half, intersecting it with the polygon, then calculating the midpoint of the longest line produced by the intersection. For lines, the non-endpoint vertex closest to the line’s centroid is returned if the line has interior points, or an endpoint is returned otherwise.
For multi-geometries or collections, the interior points of the constituent components are calculated, and one of those is returned (for MultiPolygons, it’s the point that’s the midpoint of the longest intersection of the intersection lines of any of the constituent polygons, as described above; for all others, the interior point closest to the collection’s centroid is used).
Examples
use geo::InteriorPoint;
use geo::{point, polygon};
// rhombus shaped polygon
let polygon = polygon![
(x: -2., y: 1.),
(x: 1., y: 3.),
(x: 4., y: 1.),
(x: 1., y: -1.),
(x: -2., y: 1.),
];
assert_eq!(
Some(point!(x: 1., y: 2.)),
polygon.interior_point(),
);
Required Associated Types
Required Methods
fn interior_point(&self) -> Self::Output
fn interior_point(&self) -> Self::Output
Calculates a representative point inside the Geometry
Examples
use geo::InteriorPoint;
use geo::{line_string, point};
let line_string = line_string![
(x: 40.02f64, y: 116.34),
(x: 40.02f64, y: 118.23),
(x: 40.02f64, y: 120.15),
];
assert_eq!(
Some(point!(x: 40.02, y: 118.23)),
line_string.interior_point(),
);
Implementors
sourceimpl<T> InteriorPoint for GeometryCollection<T> where
T: GeoFloat,
impl<T> InteriorPoint for GeometryCollection<T> where
T: GeoFloat,
sourceimpl<T> InteriorPoint for LineString<T> where
T: GeoFloat,
impl<T> InteriorPoint for LineString<T> where
T: GeoFloat,
sourceimpl<T> InteriorPoint for MultiLineString<T> where
T: GeoFloat,
impl<T> InteriorPoint for MultiLineString<T> where
T: GeoFloat,
sourceimpl<T> InteriorPoint for MultiPoint<T> where
T: GeoFloat,
impl<T> InteriorPoint for MultiPoint<T> where
T: GeoFloat,
use geo::InteriorPoint;
use geo::{MultiPoint, Point};
let empty: Vec<Point> = Vec::new();
let empty_multi_points: MultiPoint<_> = empty.into();
assert_eq!(empty_multi_points.interior_point(), None);
let points: MultiPoint<_> = vec![(5., 1.), (1., 3.), (3., 2.)].into();
assert_eq!(points.interior_point(), Some(Point::new(3., 2.)));