You can define geometries using macros like polygon! and line_string! and perform operations like convex_hull() on them. The crate supports various algorithms including:
- Topological Relationships: DE-9IM support, containment, and intersection.
- Affine Operations: Scale, rotate, skew, and translate.
- Boolean Operations: Clip, union, difference, intersection, and xor.
- Buffer/Offset: Buffer and offset operations on geometries.
- Geometry Repair: Repairing invalid polygons/multipolygons using constrained Delaunay triangulation.
- Clustering: DBSCAN and k-means.
- Distance/Length: Euclidean, spherical, haversine, and other non-planar calculations.
- Projections: Coordinate reference system conversion via PROJ.
- IO: Integration with
geojson and geozero crates.
// primitives
use geo::{line_string, polygon};
// algorithms
use geo::ConvexHull;
// An L shape
let poly = polygon![
(x: 0.0, y: 0.0),
(x: 4.0, y: 0.0),
(x: 4.0, y: 1.0),
(x: 1.0, y: 1.0),
(x: 1.0, y: 4.0),
(x: 0.0, y: 4.0),
(x: 0.0, y: 0.0),
];
// Calculate the polygon's convex hull
let hull = poly.convex_hull();
assert_eq!(
hull.exterior(),
&line_string![
(x: 4.0, y: 0.0),
(x: 4.0, y: 1.0),
(x: 1.0, y: 4.0),
(x: 0.0, y: 4.0),
(x: 0.0, y: 0.0),
(x: 4.0, y: 0.0),
]
);