Bug: turf/intersect 6.1.3 fails due to martinez.intersection returning invalid polygon
See original GitHub issueThis is likely related to #1394
martinez.intersection may return a list of coordinates that is not a valid polygon. see here for the polygons causing issue: https://gist.github.com/jomel/fd12af66b2d8519f0419015fac563e7d
const intersect = require('@turf/intersect').default;
intersect(polygon1, polygon2);
results in
Error : 'Each LinearRing of a Polygon must have 4 or more Positions.'
I’ve narrowed it down to
let intersection = martinez.intersection(geom1.coordinates, geom2.coordinates);
https://github.com/Turfjs/turf/blob/master/packages/turf-intersect/index.ts#L52
returning
[[[[[[0.656784,51.561146],[0.657001,51.560858],[0.657391,51.560977],[0.657562,51.560767],[0.657145,51.560639],[0.657238,51.560525],[0.6568784588933171,51.560518700155825],[0.656997802573544,51.560360135547825],[0.657207,51.560361],[0.657205,51.560501],[0.657899,51.560714],[0.657584,51.561104],[0.65779,51.561168],[0.658176,51.56069],[0.658606,51.560818],[0.658553,51.560951],[0.658552,51.560955],[0.658551,51.560958],[0.65855,51.560962],[0.65855,51.560976],[0.658551,51.560979],[0.658552,51.560983],[0.658553,51.560986],[0.658555,51.56099],[0.658557,51.560993],[0.658876,51.561546],[0.6584919499757166,51.56157188198154],[0.658501,51.561511],[0.658495,51.561501],[0.6584314599374823,51.5614094720528],[0.658483,51.561406],[0.658465,51.561311],[0.658258,51.560948],[0.658022,51.561241],[0.657832,51.561182],[0.657747,51.561287],[0.657399,51.561179],[0.657306,51.561299],[0.656784,51.561146]]]]]]
which seems to have one or two sets of [ ] too many? Yeah, I know it’s a problem with martinez, but can’t turf be smart enough to handle this?
In my case swapping the order of polygons in the call to intersect() does not solve the problem (as it id in #1394 )
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Looks like there is the same problem for the booleanContains function
Resolved in 6.3.0 onwards