What is @mapbox/geojson-extent?
@mapbox/geojson-extent is an npm package that provides utilities for calculating the bounding box of GeoJSON objects. It is useful for determining the spatial extent of geographic data represented in GeoJSON format.
What are @mapbox/geojson-extent's main functionalities?
Calculate Bounding Box
This feature allows you to calculate the bounding box of a GeoJSON object. The bounding box is represented as an array of four numbers: [minX, minY, maxX, maxY].
const geojsonExtent = require('@mapbox/geojson-extent');
const geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": {
"prop0": "value0"
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0],
[103.0, 1.0],
[104.0, 0.0],
[105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
}
]
};
const bbox = geojsonExtent(geojson);
console.log(bbox); // Output: [102, 0, 105, 1]
Other packages similar to @mapbox/geojson-extent
turf-bbox
turf-bbox is a module from the Turf.js library that calculates the bounding box of any GeoJSON object. It offers similar functionality to @mapbox/geojson-extent but is part of a larger suite of geospatial analysis tools provided by Turf.js.
geojson-bbox
geojson-bbox is a lightweight npm package that calculates the bounding box of GeoJSON objects. It is similar to @mapbox/geojson-extent in terms of functionality but is more focused on simplicity and minimalism.
geojson-extent
Compute an extent given a GeoJSON object.
install
npm install --save @mapbox/geojson-extent
example
Live example with Mapbox Static Map API
var geojsonExtent = require('geojson-extent');
geojsonExtent({ type: 'Point', coordinates: [0, 0] });
bin
Provides a binary that takes GeoJSON as stdin and returns a JSON stringified
array of extent data.
$ npm install -g geojson-extent
$ geojson-extent < file.geojson
Given an argument of leaflet
, this will return Leaflet-formatted data instead.
$ geojson-extent leaflet < file.geojson
api
extent(geojson)
Given any valid GeoJSON object, return bounds in the form [WSEN]
.
Invalid objects will return null
.
extent.polygon(geojson)
Given any valid GeoJSON object, return bounds in the form of a GeoJSON polygon object.
Invalid objects will return null
.
extent.bboxify(geojson)
Add bounding boxes to all
appropriate GeoJSON objects - Feature, FeatureCollection, and Geometry.