pub fn unary_union<'a, B: BooleanOps + 'a>(
boppables: impl IntoIterator<Item = &'a B>,
) -> MultiPolygon<B::Scalar>
Expand description
Efficient union of many adjacent / overlapping geometries
This is typically much faster than union
ing a bunch of geometries together one at a time.
Note: Geometries can be wound in either direction, but the winding order must be consistent, and each polygon’s interior rings must be wound opposite to its exterior.
See Orient for more information.
§Arguments
boppables
: A collection of Polygon
or MultiPolygons
to union together.
returns the union of all the inputs.
§Examples
use geo::algorithm::unary_union;
use geo::wkt;
let right_piece = wkt!(POLYGON((4. 0.,4. 4.,8. 4.,8. 0.,4. 0.)));
let left_piece = wkt!(POLYGON((0. 0.,0. 4.,4. 4.,4. 0.,0. 0.)));
// touches neither right nor left piece
let separate_piece = wkt!(POLYGON((14. 10.,14. 14.,18. 14.,18. 10.,14. 10.)));
let polygons = vec![left_piece, separate_piece, right_piece];
let actual_output = unary_union(&polygons);
let expected_output = wkt!(MULTIPOLYGON(
// left and right piece have been combined
((0.0 0.0, 8.0 0.0, 8.0 4.0, 0.0 4.0, 0.0 0.0)),
// separate piece remains separate
((14.0 10.0, 18.0 10.0, 18.0 14.0, 14.0 14.0, 14.0 10.0))
));
assert_eq!(actual_output, expected_output);