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:Western edge in degrees (WGS84) or units of the coordinate system. Must be less than
maxLongitude for a valid box.Southern edge in degrees.
Eastern edge in degrees.
Northern edge in degrees.
Static factory methods
worldWGS84()
Creates a bounding box spanning the full WGS84 extent:(-180, -90, 180, 90).
worldWebMercator()
Creates a bounding box spanning the full Web Mercator extent in meters.Properties
Values are accessed through getter/setter methods:| Getter | Setter | Description |
|---|---|---|
getMinLongitude(): number | setMinLongitude(v: number) | Western edge |
getMaxLongitude(): number | setMaxLongitude(v: number) | Eastern edge |
getMinLatitude(): number | setMinLatitude(v: number) | Southern edge |
getMaxLatitude(): number | setMaxLatitude(v: number) | Northern edge |
getLongitudeRange(): number—maxLongitude - minLongitudegetLatitudeRange(): number—maxLatitude - minLatitude
Methods
buildEnvelope()
Converts the bounding box to aGeometryEnvelope from the @ngageoint/simple-features-js package.
union()
Returns the smallest bounding box that contains both this box and the provided box. Returnsnull if the union would have zero area.
The other bounding box to merge with.
overlap()
Returns the intersection of this bounding box and the provided box, ornull if they do not overlap.
The other bounding box.
When
true, touching edges (zero-area overlap) are allowed. Defaults to false.intersects()
Returnstrue if this bounding box intersects the provided box.
contains()
Returnstrue if this bounding box fully contains the provided box (inclusive on all edges).
isPoint()
Returnstrue when minLongitude === maxLongitude and minLatitude === maxLatitude — i.e. the bounding box represents a single point.
getCentroid()
Returns the geometric centroid of the bounding box as aPoint.
A
Point from @ngageoint/simple-features-js with x (longitude) and y (latitude) coordinates.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.The source projection (the CRS the current coordinates are in).
The target projection to transform into.
A new
BoundingBox in the target projection.toGeoJSON()
Returns the bounding box as a GeoJSONFeature with a Polygon geometry.
copy()
Creates a deep copy of the bounding box.equals()
Returnstrue if the provided bounding box has identical coordinate values.
squareExpand()
Expands the bounding box so that its width and height are equal (a square), with an optional percentage buffer added on each side.Edge buffer as a fraction. For example,
0.1 adds a 10% buffer on each side. Defaults to 0.0.