Rust API
Accepts geo_types geometries and returns an Option<Coord<f64>>.
interior_point(geometry)
Computes an interior point of the given geometry, dispatching by dimension.
Parameters:
geometry: &Geometry<f64>— A reference to ageo_types::Geometry
Returns: Option<Coord<f64>> — The interior point coordinate, or None if empty
use interior_point::interior_point;
use geo_types::{Geometry, Polygon, LineString};
let poly = Polygon::new(
LineString::from(vec![
(0.0, 0.0),
(6.0, 0.0),
(6.0, 2.0),
(2.0, 2.0),
(2.0, 8.0),
(0.0, 8.0),
(0.0, 0.0),
]),
vec![],
);
let result = interior_point(&poly.into());
// => Some(Coord { x: 1.0, y: 5.0 })Returns None for empty geometries:
use geo_types::{Geometry, GeometryCollection};
let empty = Geometry::GeometryCollection(GeometryCollection::<f64>(vec![]));
assert_eq!(interior_point::interior_point(&empty), None);verify_interior_point(point, geometry)
Checks a point against the geometry it was computed from, using a point-in-polygon locator that shares no code with the algorithm that produced the point. It answers a question about this crate's output, not about the input's OGC validity — an invalid geometry can still yield a point that verifies.
Parameters:
point: Option<Coord<f64>>— the coordinate to check, normally the return value ofinterior_pointgeometry: Option<&Geometry<f64>>— the geometry the point should lie on or in, orNone
Returns: Verification — one of four outcomes:
| Value | Reached when |
|---|---|
Verification::Interior | an area geometry, and the point lies inside it |
Verification::OnGeometry | the point lies on the boundary of an area geometry, or is a vertex of a line or point geometry |
Verification::OffGeometry | the point lies outside an area geometry, or matches no vertex of a line or point geometry |
Verification::Unverifiable | point is None, geometry is None, or every element of geometry is empty |
Compare the outcome against the variant you mean. OffGeometry and Unverifiable are not the same thing — OffGeometry is a failed check, Unverifiable the absence of one — which is why the CLI leaves an unverifiable record at exit code 0. The Display output is the four kebab-case strings interior, on-geometry, off-geometry and unverifiable, which is what the CLI prints.
use interior_point::{interior_point, verify_interior_point, Verification};
use geo_types::{Geometry, LineString, Polygon};
let geometry: Geometry<f64> = Polygon::new(
LineString::from(vec![(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0), (0.0, 0.0)]),
vec![],
)
.into();
let point = interior_point(&geometry);
assert_eq!(verify_interior_point(point, Some(&geometry)), Verification::Interior);Some(&geometry) rather than &geometry: one signature serves both the library caller and the CLI, whose records carry an optional geometry because GeoJSON permits a Feature with none.
centroid_first_interior_point(geometry)
Computes the geometry's centroid and returns it when it lies strictly inside the geometry; otherwise falls back to interior_point. A representative point is more useful when it is the centroid: the fallback returns whichever point the scanline algorithm lands on, which depends on how the algorithm is implemented, so this entry point reaches for it as rarely as it can.
Parameters:
geometry: &Geometry<f64>— A reference to ageo_types::Geometry
Returns: Option<Coord<f64>> — The point, or None if empty
Area geometries take the centroid only when it locates as interior. Strictly inside means the interior and nothing else: a centroid lying exactly on the boundary is rejected and interior_point runs. Line and point geometries delegate to interior_point unchanged, since at those dimensions it already returns the vertex nearest the centroid.
use geo_types::{Geometry, LineString, Polygon};
use interior_point::{centroid_first_interior_point, interior_point};
let triangle: Geometry<f64> = Polygon::new(
LineString::from(vec![(0.0, 0.0), (6.0, 0.0), (0.0, 6.0), (0.0, 0.0)]),
vec![],
)
.into();
centroid_first_interior_point(&triangle); // => Some(Coord { x: 2.0, y: 2.0 })
interior_point(&triangle); // => Some(Coord { x: 1.5, y: 3.0 })The return value is the point alone; which of the two branches produced it is not reported. A caller that needs to know can compare the result against a centroid it computes itself. Every path that does not accept the centroid ends in interior_point, so a degenerate geometry behaves exactly as it does through interior_point.
Type Reference
| Type | Definition |
|---|---|
Geometry<f64> | geo_types::Geometry<f64> |
Coord<f64> | geo_types::Coord { x: f64, y: f64 } |
Verification | an enum: Interior, OnGeometry, OffGeometry, Unverifiable |
With the default features, interior_point, verify_interior_point, Verification and centroid_first_interior_point are the crate's whole public surface; the locator behind the check is crate-internal and is not documented here as a callable item.