turf icon indicating copy to clipboard operation
turf copied to clipboard

booleanIntersects between v6 and v7 return different values

Open aaronkyle opened this issue 1 year ago • 3 comments

Please provide the following when reporting an issue:

I was using Turf@7 when I discovered this issue. I can verify that it doesn't happen with Turf@6.

Here are two Observable notebooks with the same code, but different Turf.js versions:

  • Turf@7: https://observablehq.com/d/7c4d04a94a359361
  • Turf@6: https://observablehq.com/d/979097a9b1512042

With Turf@6, my bounding box allows me to filter a source data file by objects correctly.

Screenshot from 2024-08-12 20-25-15

In Turf@7, I am seeing returns from the opposite side of the globe.

Screenshot from 2024-08-12 20-24-37

aaronkyle avatar Aug 13 '24 00:08 aaronkyle

Hi @aaronkyle. Thanks for reporting this. Can't actually view your examples unless I log in, which I'd rather not have to :) Can you post to a https://jsfiddle.net instead?

Can you also please attach the Geojson data going in to and returned from booleanIntersects? And if not a JSFiddle, a snippet of the surrounding code as well.

smallsaucepan avatar Aug 15 '24 00:08 smallsaucepan

Hi @smallsaucepan . Thank you for looking into this. I apologize that I missed making one of those notebooks public. I fixed them so that you can review without logging in. The source .geojson is 40MB, so rather large to attach, however it is included as a file attachment on the notebook. I'll also link to it from a GitHub repo.

To decrease all the clutter from the notebook where I discovered the issue, I have created a minimal notebook example here: https://observablehq.com/d/ae03f49d4dd9b456

In this example, I load both versions of Turf (6 and 7) and use them in otherwise identical functions, where they return different outputs, namely:

function getVisibleFeatures_turf6(geojson, boundingBox) {
  if (!geojson || !geojson.features || !boundingBox) {
    throw new Error('Invalid arguments');
  }

  // Create a turf bounding box polygon
  const bboxPolygon = turf6.bboxPolygon([
    boundingBox.west,
    boundingBox.south,
    boundingBox.east,
    boundingBox.north
  ]);

  // Filter features based on whether they intersect with the bounding box polygon
  const visibleFeatures = geojson.features.filter(feature => {
    // Check if the feature intersects with the bounding box polygon
    return turf6.booleanIntersects(bboxPolygon, feature);
  });

  // Return the filtered GeoJSON object
  return {
    type: 'FeatureCollection',
    features: visibleFeatures
  };
}

(repeats for Turf7)

These outputs are attached (and can also be pulled from the notebook). visibleFeatures_turf7.json visibleFeatures_turf6.json

Here's the link to the source .geojson: https://github.com/aaronkyle/kba-table-view/blob/master/src/kba-2022-10-poly-simp.geojson

Hope this helps!

aaronkyle avatar Aug 15 '24 01:08 aaronkyle

Looking back at the returned features, the geometries do indeed have negative values, so my original assumption about what is happening to cause these differences is incorrect. I'll update the title of this issue.

aaronkyle avatar Aug 15 '24 02:08 aaronkyle