Bounding Box Utility Functions

0.20.2 · active · verified Sun Apr 19

bbox-fns is a lightweight JavaScript library offering a collection of modular utility functions for common geospatial bounding box operations. Bounding boxes are consistently represented as a four-element array: `[xmin, ymin, xmax, ymax]`. Currently at version 0.20.2, the library maintains a relatively frequent release cadence, often introducing new functions or minor fixes, with updates typically occurring every few weeks or months. Its key differentiator lies in its 'super light-weight' design and modular structure, where most functions reside in their own file. This approach facilitates granular imports, allowing developers to include only the specific utilities needed, thereby contributing to smaller bundle sizes. It focuses exclusively on core bounding box manipulations rather than broader GIS features.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates calculating a bounding box from an array of points, handling NaN values, then calculating its area, and finally checking for intersection with another bounding box.

import bboxArray from 'bbox-fns/bbox-array.js';
import bboxArea from 'bbox-fns/bbox-area.js';
import booleanIntersects from 'bbox-fns/boolean-intersects.js';

// Define a set of points for a polygon ring
const points = [
  [-180, 86.06126914660831],
  [-180, 85.66739606126914],
  [NaN, 84.87964989059081], // Point with NaN value
  [-179, 84.48577680525165]
];

// Calculate the bounding box, skipping NaN values
const calculatedBbox = bboxArray(points, { nan_strategy: 'skip' });
console.log('Calculated Bounding Box (skipping NaN):', calculatedBbox);

// Calculate the area of the bounding box
const area = bboxArea(calculatedBbox);
console.log('Area of the bounding box:', area);

// Define another bounding box
const referenceBbox = [-10, -20, 10, 20];

// Check if the calculated bbox intersects with the reference bbox
const intersects = booleanIntersects(calculatedBbox, referenceBbox);
console.log('Does the calculated bbox intersect with reference bbox?', intersects);

view raw JSON →