@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
35 lines • 1.38 kB
JavaScript
import { isFeature } from "../helpers/geo.js";
import { booleanOverlap as turfBoolOverlap } from "@turf/turf";
import deepEqual from "fast-deep-equal";
export async function booleanOverlap(featureAInput, featureBInput, idProperty) {
// Normalize input to array
const featuresA = Array.isArray(featureAInput)
? featureAInput
: [featureAInput];
const featuresB = Array.isArray(featureBInput)
? featureBInput
: [featureBInput];
const overlapFeatures = [];
const overlapIds = [];
for (const featureA of featuresA) {
for (const featureB of featuresB) {
// Don't test overlap if we already know it does
if (isFeature(featureB) && idProperty) {
const fb = featureB;
const idB = fb.properties ? fb.properties[idProperty] : null;
if (!overlapIds.includes(idB) && turfBoolOverlap(featureA, featureB)) {
overlapFeatures.push(featureB);
overlapIds.push(idB);
}
}
else {
if (!overlapFeatures.some((of) => deepEqual(featureB, of)) &&
turfBoolOverlap(featureA, featureB)) {
overlapFeatures.push(featureB);
}
}
}
}
return overlapFeatures;
}
//# sourceMappingURL=booleanOverlap.js.map