Open qihua opened 3 years ago
The heavy lifting for this is done by the polygon-clipping
library, which already has open bug reports about this as well. In this bug report against polygon-clipping
, I found a solution which solved the problem for me.
The solution is to truncate the coordinates involved as apparently the bug is triggered by floating point number calculations.
Turf.js includes a truncate
method for this purpose. It has a good default value of 6 digits beyond the decimal, which is likely all you need anyway-- that's about a precision down to a meter. Is your underlying data actually more accurate than that?
https://stackoverflow.com/a/1947615/254318
Until a better fix is developed, the docs for turf.union
could be updated to recommend using truncate if there's a problem.
@turf/turf 6.2.0-alpha2
Uncaught Error: Unable to complete output ring starting at [-160.6896965377851, 40.88860081193033]. Last matching segment found ends at [-134.07528251720086, 11.208361735012105].
I found that if you delete [-138.73721748279917,2.078378225075909] in b, it’s ok, so strange.Is it because [-138.73721748279917,2.078378225075909] and [-138.73721748279914,2.0783782250758946] are about the same value?