turf.union
What is turf.union?
turf.union merges two or more polygons into a single Polygon or MultiPolygon, combining overlapping or adjacent geometry. It is the GeoJSON equivalent of ST_Union in PostGIS and uses the robust Martinez-Rueda algorithm via polygon-clipping.
turf.union(featureCollection) → Feature<Polygon | MultiPolygon> | nullRecent versions accept a FeatureCollection<Polygon>; legacy versions took a variadic list of polygon arguments. Confirm the signature in your installed version.
When would you use turf.union?
Use turf.union to combine geofences into a single coverage area, merge drawn selections as a user adds to a shape, or collapse a multi-polygon search region into a single boundary. It is also the go-to operation for "total footprint" calculations — e.g., combining building outlines to compute total rooftop area.
Unlike turf.dissolve, turf.union does not require inputs to share edges exactly and handles overlapping polygons gracefully.
undefinedFAQs
What is the difference between union and dissolve?
turf.union handles arbitrary polygons — overlapping, disjoint, or adjacent — and always produces a single merged output. turf.dissolve expects a tiled input with shared edges and can filter by an attribute. Use dissolve for attribute-based grouping; union for free-form merging.
How do I install just union?
npm install @turf/union. It depends on @turf/helpers and polygon-clipping.
Can it merge more than two polygons?
Yes — pass any number of polygons in the FeatureCollection. Internally the algorithm unions them pairwise.
What if inputs are disjoint?
The result is a MultiPolygon containing all disjoint parts. You can split with turf.flatten if you need individual Polygon features.