ptmbox
v0.1.3
Published
Compute the bounding box of a GeoJsonObject
Readme
ptmbox
Compute the bounding box of a GeoJSON object.
Install
Install from npm:
npm install ptmboxOr from this repository (install dev deps and build):
npm install
npm run buildUsage
CommonJS (Node):
const ptmbox = require('ptmbox');
// or require the local build during development:
// const ptmbox = require('./lib/index.js');
const bbox = ptmbox.bbox({ type: 'Point', coordinates: [1, 2] });
console.log(bbox); // [1, 2, 1, 2]ESM / TypeScript:
import ptmbox from 'ptmbox';
const box = ptmbox.bbox({ type: 'LineString', coordinates: [[0,0],[2,3]] });
console.log(box); // [0, 0, 2, 3]TypeScript types are provided via lib/index.d.ts.
API
bbox(geoJson: GeoJSON): GeoJSON.BBox- Returns a bounding box in the format
[minX, minY, maxX, maxY]. - Accepts any GeoJSON object:
Point,LineString,Polygon,MultiPoint,MultiLineString,MultiPolygon,GeometryCollection,Feature, andFeatureCollection.
- Returns a bounding box in the format
Examples
Point:
ptmbox.bbox({ type: 'Point', coordinates: [5, 6] }); // [5, 6, 5, 6]Polygon:
ptmbox.bbox({ type: 'Polygon', coordinates: [[[0,0],[3,0],[3,4],[0,0]]] }); // [0, 0, 3, 4]FeatureCollection:
ptmbox.bbox({
type: 'FeatureCollection',
features: [
{ type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0] }, properties: null },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [2, 1] }, properties: null },
],
}); // [0, 0, 2, 1]Tests
Run the test suite with:
npm testBuild
Compile TypeScript sources to lib/:
npm run buildContributing
Contributions welcome. Please open issues or pull requests on the repository.
License
ISC
