You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is an issue with the upstream polygon-clipping library, which was probably swapped in as the implementation for turf.union between the two versions you are using. See this related issue and feel free to add to it with your example -- mfogel/polygon-clipping#111.
Resolving this would need to happen upstream it looks like so I can leave this issue open.
When I hit this error, I can usually workaround it by breaking down the inputs into smaller chunks. In your case it might be sufficient to split the first or second input from one into two multipolygons, each with half the features. Then call union for each half, and combine the partial results with a final union. You can increase the number of chunks (reducing the input size for each call) until you find something that works. A little clunky but functional.
I use this chunking technique for intersection and maybe for difference as well. You just have to be aware of what the operation is doing to know how to combine the partial results.
Here's an example of a chunk function (typescript) that takes an array of anything and returns an array of arrays with length no greater than chunkSize. The last chunk will have the remainder. Modify to suit your needs.
/**
* Splits an array into chunks of size
*/
export function chunk<T>(array: T[], chunkSize: number): T[][] {
const R: any[] = [];
for (let i = 0, len = array.length; i < len; i += chunkSize)
R.push(array.slice(i, i + chunkSize));
return R;
}
I've tried this both on 6.5.0 and 7.0.0-alpha0 with the same bug. Attaching two geojson objects that create the bug when called with union(featureCollection([geom1.type === 'Feature' ? geom1 : feature(geom1), geom2.type === 'Feature' ? geom2 : feature(geom2)]))
@turf/union@6.5.0 gives 'RangeError: Maximum call stack size exceeded' error after upgrading from @turf/union@5.1.5, with same input parameters.
Version 6.5.0 snippet of code that calls turf.union fails with the error:
Version 5.1.5 snippet of code that calls turf.union works:
The text was updated successfully, but these errors were encountered: