Skip to main content

Crate interior_point

Crate interior_point 

Source
Expand description

§interior-point

Compute an interior point (representative point) of a geometry.

Ported from the JTS Topology Suite InteriorPoint algorithm. Geometries are geo-types, which is the crate’s only required dependency; the cli feature adds the rest.

§Usage

Add to Cargo.toml:

[dependencies]
interior-point = "1.0"
geo-types = "0.7"

or using cargo add:

cargo add interior-point
cargo add geo-types
use geo_types::{polygon, Geometry};
use interior_point::interior_point;

let poly = polygon![
    (x: 0.0, y: 0.0),
    (x: 6.0, y: 0.0),
    (x: 6.0, y: 2.0),
    (x: 2.0, y: 2.0),
    (x: 2.0, y: 8.0),
    (x: 0.0, y: 8.0),
    (x: 0.0, y: 0.0),
];

let pt = interior_point(&Geometry::Polygon(poly));
assert!(pt.is_some());

An empty geometry returns None.

§API

ItemSignatureReturns
interior_point(geometry: &Geometry<f64>) -> Option<Coord<f64>>a point inside area geometries, or on linear and point ones
verify_interior_point(point: Option<Coord<f64>>, geometry: Option<&Geometry<f64>>) -> VerificationInterior, OnGeometry, OffGeometry or Unverifiable
centroid_first_interior_point(geometry: &Geometry<f64>) -> Option<Coord<f64>>the geometry’s centroid when it lies strictly inside, and interior_point when it does not

Those three functions and the Verification they answer with are the crate’s whole public surface with the default features. Verification runs through a point-in-polygon locator that shares no code with the algorithm that produced the point, and checks this crate’s own output rather than the input’s OGC validity.

Full signatures, the four verification outcomes and the reasoning behind each entry point: API reference.

§CLI

This crate also bundles an interior-point command-line binary, behind a cli feature that is not in default; cargo install interior-point alone installs nothing, so build or install it with --features cli:

cargo install interior-point --features cli

It reads WKT or GeoJSON — as a literal, a file, or on stdin — and writes GeoJSON by default or one WKT geometry per line. See the CLI page for every flag, the output shapes and the exit codes.

§Documentation

Full documentation: sanak.github.io/interior-point

§Development

This crate was developed with the assistance of Claude Code; every ported member is anchored to its JTS counterpart and checked against JTS’s own test resources.

§License

MIT

This crate contains algorithms ported from JTS (EPL 2.0 / EDL 1.0).

Enums§

Verification
Where a computed interior point sits relative to its geometry.

Functions§

centroid_first_interior_point
Computes a representative point of a geometry, preferring its centroid.
interior_point
Computes a location of an interior point in a Geometry. Handles all geometry types.
verify_interior_point
Reports where point sits relative to geometry.