@turf/intersect throws error "Each LinearRing of a Polygon must have 4 or more Positions"
See original GitHub issuePlease provide the following when reporting an issue:
- The version of Turf you are using, and any other relevant versions.
- GeoJSON data as a gist file or geojson.io (filename extension must be
.geojson
). - Snippet of source code or for complex examples use jsfiddle.
Hi,
I created a stackblitz with a “minimal” reproduction scenario. I think what is happening is that both polygons intersect only on a lineString which then internally fails the conversion to a polygon which is understandable. However, I would expect that either null is returned or even the resulting lineString. Just letting the polygon helper function throw an error is not a very good DX and hard to debug.
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
turf intersect: Each LinearRing of a Polygon must have 4 or ...
The error that is thrown when you don't have any internal rings is "Each LinearRing of a Polygon must have 4 or more...
Read more >D3.js with Turf.js error: "Uncaught (in promise) Error: Each ...
Uncaught (in promise) Error: Each LinearRing of a Polygon must have 4 or more Positions. I've tried D3's d3.geoContain() but it threw false ......
Read more >Each LinearRing of a Polygon must have 4 or more Positions
turf intersect : Each LinearRing of a Polygon must have 4 or more Positions.
Read more >Each Linearring Of A Polygon Must Have 4 Or More Positions.
Turf's logic then tries to create a polygon with an incorrect coordinate array which throws the linear ring error.Here's a test case for...
Read more >Union GeoJSON polygons - openlayers - GIS Stack Exchange
If I try with just: turf.polygon(geojsonObject) I get the error: Each LinearRing of a Polygon must have 4 or more Positions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@stebogit Thank you for the hint. We did not know that turf can only handle 6 decimal places “safely”. Truncating seems to be the solution for my problem. I also tried it with a simplified example of two polygons intersecting on a lineString and that does not throw an error. Thanks for the help guys!
@sroettering it looks like the issue is related to the precision of the coordinates. Try truncating the coordinates in your polygons:
Not sure if there’s a formal statement in the docs (maybe there should be one), however Turf - as per GeoJSON specs - generally assumes
Feature
s don’t have more than 6 decimals, which is like 10cm spatial resolution. In fact I’ve seen other instances where too many decimals could generate unexpected results like here.