Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9.19k stars 934 forks source link

@turf/union : ambiguity in the documentation #2657

Open Cooya opened 1 month ago

Cooya commented 1 month ago

turf.union() can only merge 2 polygons at once (https://stackoverflow.com/questions/68005988/geojson-turf-merge-multiple-polygons-to-one-polygon-keeping-hole). It should be specified in the documentation (https://www.npmjs.com/package/@turf/union) and in the TypeScript interface file to avoid invalid merges with more than 2 polygons.

twelch commented 1 month ago

I agree the API docs don't look quite right. That said, you can union more than 2 polygons. You can include as many polygons as you want in your featureCollection input. This is as of Turf 7.0

var union = turf.union(turf.featureCollection([poly1, poly2, poly3, ...]))
Cooya commented 1 month ago

My bad, turf.union() can actually union more than 2 polygons and works like a charm. It was a mistake in my code. My apologies for the inconvenience. I am closing the issue.

twelch commented 1 month ago

Thanks, let’s leave this open for improvement of the docs, multiple people have stumbled here since v7 release