Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

booleanIntersects between v6 and v7 return different values #2700

Open
aaronkyle opened this issue Aug 13, 2024 · 3 comments
Open

booleanIntersects between v6 and v7 return different values #2700

aaronkyle opened this issue Aug 13, 2024 · 3 comments

Comments

@aaronkyle
Copy link

aaronkyle commented Aug 13, 2024

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:

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

@smallsaucepan
Copy link
Member

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 smallsaucepan changed the title Turf@7 (boolean-intersects?) appears to drop negative lat/long values booleanIntersects v7 appears to drop negative lat/long values Aug 15, 2024
@aaronkyle
Copy link
Author

aaronkyle commented Aug 15, 2024

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
Copy link
Author

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 aaronkyle changed the title booleanIntersects v7 appears to drop negative lat/long values booleanIntersects between v6 and v7 return different values Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants