question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: turf/intersect 6.1.3 fails due to martinez.intersection returning invalid polygon

See original GitHub issue

This 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
arthurspcommented, Oct 10, 2019

Looks like there is the same problem for the booleanContains function

0reactions
rowanwinscommented, Jul 30, 2021

Resolved in 6.3.0 onwards

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix invalid polygon with self-intersection - Python
Fixing invalid polygons is hard because there really is no way of knowing how the polygon is supposed to be like.
Read more >
Fix invalid polygon in Shapely - python - Stack Overflow
I found a solution that works for the specific case given: >>> pp2 = pp.buffer(0) >>> pp2.is_valid True >>> pp2.exterior.coords[:] [(0.0, ...
Read more >
Invalid OGC Geometry Examples - FME Community
The GeometryValidator transformer can be used to check for features that fail to comply with the OGC geometry specifications.
Read more >
23. Validity — Introduction to PostGIS
Validity is most important for polygons, which define bounded areas and require a good deal of structure. Lines are very simple and cannot...
Read more >
Intersect Error: Invalid Topology and The table was not found
Solved: Hi all, I am having problems with Intersect. I would like to intersect two polygon feature classes. One of them is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found