UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

37 lines 1.39 kB
import Flatbush from "flatbush"; import expand from "./expand.js"; export function createIndexes(items, compositeIndexTargetBytes, compositeIndexMinChunks, flatbushNodeSize) { const index = new Flatbush(items.length, flatbushNodeSize); for (const bbox of items) { index.add(bbox[0], bbox[1], bbox[2], bbox[3]); } index.finish(); // Create composite indexes const nCompositeIndexes = Math.max(Math.round(index.data.byteLength / compositeIndexTargetBytes), compositeIndexMinChunks); const chunkSize = Math.floor(items.length / nCompositeIndexes); const compositeIndexes = []; for (let i = 0; i < nCompositeIndexes; i++) { const isLast = i === nCompositeIndexes - 1; const bboxes = isLast ? items.slice(chunkSize * i) : items.slice(chunkSize * i, chunkSize * (i + 1)); let extent = null; const index = new Flatbush(bboxes.length, flatbushNodeSize); for (const bbox of bboxes) { extent = expand(extent, bbox); index.add(bbox[0], bbox[1], bbox[2], bbox[3]); } index.finish(); compositeIndexes.push({ length: bboxes.length, offset: chunkSize * i, index: index, bbox: extent, }); } return { index, compositeIndexes, }; } //# sourceMappingURL=indexes.js.map