The bboxPolygon module is a part of Turf.js which allows you to create a polygon from a bounding box, which is defined as a set of coordinates that define the corners of a rectangle.
bboxPolygon function takes a single parameter of type Array. The array should contain coordinates for the bounding box in the format [west, south, east, north], where the west, south, east, and north values denote the corners of the bounding box.
The bboxPolygon function returns a standard GeoJSON polygon feature that encapsulates the bounding box coordinates.
var bbox = [-77, 38, -76, 39]; // [west, south, east, north]
var bboxPolygon = turf.bboxPolygon(bbox);
console.log(bboxPolygon);
Output:
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-77, 39],
[-77, 38],
[-76, 38],
[-76, 39],
[-77, 39]
]
]
}
}
In this example, we create a bounding box of [-77, 38, -76, 39] and then pass it to turf.bboxPolygon to create a polygon feature. This feature is then logged to the console.
To use the bboxPolygon module, first install Turf.js using npm:
npm install @turf/turf
You can then include it in your application using:
var turf = require('@turf/turf');