Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9.33k stars 943 forks source link

booleanIntersects returns false even though features visually intersect #2424

Closed noisyneuron closed 1 month ago

noisyneuron commented 1 year ago

In using booleanIntersects for a line and polygon, it appears that the geodesic/rhumb(?) line is used for calculation rather than the visual line

In the screenshot, the smaller polygon (poly1) returns false where as the larger one (poly2) returns true. Code sandbox: https://codesandbox.io/s/turftests-zbnhot?file=/src/index.js

Screen Shot 2023-04-04 at 12 30 50 PM

Turf v6.5.0

JamesLMilner commented 1 year ago

I don't think this is an issue with geodesics as the LineString still intersects in a globe view: Screenshot_20230425_205525

The issue can be simplified to this CodeSandbox: https://codesandbox.io/s/turf-issue-2424-p1w4pe?file=/src/index.js

smallsaucepan commented 6 months ago

Dug into this a bit further. Looking at the test data using one reference system (EPSG:3395) "WGS 84 / World Mercator" shows intersections for both:

Screenshot 2024-05-08 at 12 02 15 am

Using another reference system (EPSG:4326) "WGS 84" shows only an intersection with the large rectangle:

Screenshot 2024-05-08 at 12 02 41 am

I'm going to guess the math sweepline-intersections uses is matched more closely by the latter projection.

It raises the question of how should Turf interpret a line between two points: as a constant bearing rhumb line projected on a flat surface, or as a great circle segment on a sphere? Given it's your use case @noisyneuron, what were you expecting with the data you had?

FYI this is what the great circle path looks like:

Screenshot 2024-05-07 at 5 39 59 pm

smallsaucepan commented 1 month ago

Closing in lieu of further background from OP. Please reopen if more details come to light.