What is @turf/bbox-polygon?
@turf/bbox-polygon is a module from the Turf.js library that allows you to create a Polygon feature from a bounding box (bbox). This is useful for geographic data manipulation and visualization, especially when you need to represent an area defined by a bounding box as a polygon.
What are @turf/bbox-polygon's main functionalities?
Create Polygon from Bounding Box
This feature allows you to create a Polygon feature from a bounding box. The bounding box is defined by an array of four numbers: [minX, minY, maxX, maxY]. The resulting polygon can be used in various geospatial analyses and visualizations.
const turf = require('@turf/bbox-polygon');
const bbox = [0, 0, 10, 10];
const polygon = turf(bbox);
console.log(JSON.stringify(polygon));
Other packages similar to @turf/bbox-polygon
geojson-bbox
The geojson-bbox package provides functionality to calculate the bounding box of a GeoJSON object. While it focuses on calculating the bbox from existing GeoJSON data, it does not create polygons from bboxes like @turf/bbox-polygon.
bbox
The bbox package is a lightweight utility for working with bounding boxes. It provides methods to create, manipulate, and query bounding boxes, but it does not offer the capability to convert a bbox directly into a polygon as @turf/bbox-polygon does.
geojson-utils
The geojson-utils package offers a variety of utilities for working with GeoJSON data, including calculating bounding boxes and other spatial operations. However, it does not specifically focus on converting bboxes to polygons like @turf/bbox-polygon.
@turf/bbox-polygon
bboxPolygon
Takes a bbox and returns an equivalent polygon.
Parameters
-
bbox
BBox extent in [minX, minY, maxX, maxY] order
-
options
Object Optional parameters (optional, default {}
)
options.properties
Properties Translate properties to Polygon (optional, default {}
)options.id
(string | number) Translate Id to Polygon (optional, default {}
)
Examples
var bbox = [0, 0, 10, 10];
var poly = turf.bboxPolygon(bbox);
var addToMap = [poly]
Returns Feature<Polygon> a Polygon representation of the bounding box
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this single module individually:
$ npm install @turf/bbox-polygon
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf