Open aaronkyle opened 3 months ago
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.
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!
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.
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.
In Turf@7, I am seeing returns from the opposite side of the globe.