Skip to main content
BoundingBox stores a rectangular spatial extent defined by minimum and maximum longitude/latitude values. It is used throughout the library as a spatial filter for queries and to describe table extents.

Constructors

The class provides several constructor overloads:
// No-arg: world WGS84 bounds (-180, -90, 180, 90)
new BoundingBox()

// Copy constructor
new BoundingBox(boundingBox: BoundingBox)

// From a geometry envelope
new BoundingBox(envelope: GeometryEnvelope)

// From a geometry object
new BoundingBox(geometry: Geometry)

// Explicit coordinates
new BoundingBox(
  minLongitude: number,
  minLatitude: number,
  maxLongitude: number,
  maxLatitude: number
)
minLongitude
number
Western edge in degrees (WGS84) or units of the coordinate system. Must be less than maxLongitude for a valid box.
minLatitude
number
Southern edge in degrees.
maxLongitude
number
Eastern edge in degrees.
maxLatitude
number
Northern edge in degrees.
import { BoundingBox } from '@ngageoint/geopackage';

// Washington D.C. area
const bbox = new BoundingBox(-77.12, 38.79, -76.91, 38.99);

// World bounds
const world = new BoundingBox();

// Copy
const copy = new BoundingBox(bbox);

Static factory methods

worldWGS84()

Creates a bounding box spanning the full WGS84 extent: (-180, -90, 180, 90).
static worldWGS84(): BoundingBox

worldWebMercator()

Creates a bounding box spanning the full Web Mercator extent in meters.
static worldWebMercator(): BoundingBox

Properties

Values are accessed through getter/setter methods:
GetterSetterDescription
getMinLongitude(): numbersetMinLongitude(v: number)Western edge
getMaxLongitude(): numbersetMaxLongitude(v: number)Eastern edge
getMinLatitude(): numbersetMinLatitude(v: number)Southern edge
getMaxLatitude(): numbersetMaxLatitude(v: number)Northern edge
Additional read-only derived values:
  • getLongitudeRange(): numbermaxLongitude - minLongitude
  • getLatitudeRange(): numbermaxLatitude - minLatitude

Methods

buildEnvelope()

Converts the bounding box to a GeometryEnvelope from the @ngageoint/simple-features-js package.
buildEnvelope(): GeometryEnvelope
const bbox = new BoundingBox(-77.12, 38.79, -76.91, 38.99);
const envelope = bbox.buildEnvelope();
// envelope.minX === -77.12, envelope.maxY === 38.99

union()

Returns the smallest bounding box that contains both this box and the provided box. Returns null if the union would have zero area.
union(boundingBox: BoundingBox): BoundingBox | null
boundingBox
BoundingBox
required
The other bounding box to merge with.
const a = new BoundingBox(-10, -10, 0, 0);
const b = new BoundingBox(-5, -5, 10, 10);
const combined = a.union(b);
// BoundingBox(-10, -10, 10, 10)

overlap()

Returns the intersection of this bounding box and the provided box, or null if they do not overlap.
overlap(boundingBox: BoundingBox, allowEmpty?: boolean): BoundingBox | null
boundingBox
BoundingBox
required
The other bounding box.
allowEmpty
boolean
When true, touching edges (zero-area overlap) are allowed. Defaults to false.

intersects()

Returns true if this bounding box intersects the provided box.
intersects(boundingBox: BoundingBox, allowEmpty?: boolean): boolean
const dc = new BoundingBox(-77.12, 38.79, -76.91, 38.99);
const nyc = new BoundingBox(-74.26, 40.49, -73.70, 40.92);

dc.intersects(nyc); // false

contains()

Returns true if this bounding box fully contains the provided box (inclusive on all edges).
contains(boundingBox: BoundingBox): boolean

isPoint()

Returns true when minLongitude === maxLongitude and minLatitude === maxLatitude — i.e. the bounding box represents a single point.
isPoint(): boolean
const point = new BoundingBox(-77.0, 38.9, -77.0, 38.9);
point.isPoint(); // true

getCentroid()

Returns the geometric centroid of the bounding box as a Point.
getCentroid(): Point
Point
Point
A Point from @ngageoint/simple-features-js with x (longitude) and y (latitude) coordinates.
const bbox = new BoundingBox(-77.12, 38.79, -76.91, 38.99);
const center = bbox.getCentroid();
// center.x ≈ -77.015, center.y ≈ 38.89
Use getDegreesCentroid() when your box is in WGS84 degrees and you want a geodetically correct centroid that accounts for the curvature of the Earth.

projectBoundingBox()

Projects the bounding box from one coordinate reference system to another and returns the transformed box.
projectBoundingBox(from: Projection, to: Projection): BoundingBox
from
Projection
required
The source projection (the CRS the current coordinates are in).
to
Projection
required
The target projection to transform into.
BoundingBox
BoundingBox
A new BoundingBox in the target projection.
import { Projections } from '@ngageoint/projections-js';

const wgs84Box = new BoundingBox(-77.12, 38.79, -76.91, 38.99);

const wgs84 = Projections.getWGS84Projection();
const webMercator = Projections.getWebMercatorProjection();

const mercatorBox = wgs84Box.projectBoundingBox(wgs84, webMercator);
// Now in EPSG:3857 meters

toGeoJSON()

Returns the bounding box as a GeoJSON Feature with a Polygon geometry.
toGeoJSON(): Feature
const bbox = new BoundingBox(-77.12, 38.79, -76.91, 38.99);
const feature = bbox.toGeoJSON();
// feature.geometry.type === 'Polygon'

copy()

Creates a deep copy of the bounding box.
copy(): BoundingBox

equals()

Returns true if the provided bounding box has identical coordinate values.
equals(obj: BoundingBox): boolean

squareExpand()

Expands the bounding box so that its width and height are equal (a square), with an optional percentage buffer added on each side.
squareExpand(bufferPercentage?: number): BoundingBox
bufferPercentage
number
Edge buffer as a fraction. For example, 0.1 adds a 10% buffer on each side. Defaults to 0.0.
squareExpand() is useful before passing a bounding box to a map viewer that requires equal-aspect tiles or thumbnails.

Build docs developers (and LLMs) love