
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@turf/bbox-clip
Advanced tools
@turf/bbox-clip is a module from the Turf.js library that allows you to clip a GeoJSON feature to a bounding box. This is useful for tasks such as extracting a specific area from a larger dataset, ensuring that features fit within a certain geographic region, or preparing data for visualization.
Clip a Polygon to a Bounding Box
This feature allows you to clip a polygon to a specified bounding box. The code sample demonstrates how to clip a polygon that spans a larger area to fit within the bounding box defined by the coordinates [-3, 53, 3, 55].
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-5, 52], [-5, 56], [5, 56], [5, 52], [-5, 52]
]]);
const bbox = [-3, 53, 3, 55];
const clipped = turf.bboxClip(polygon, bbox);
console.log(JSON.stringify(clipped));
Clip a LineString to a Bounding Box
This feature allows you to clip a LineString to a specified bounding box. The code sample demonstrates how to clip a LineString that spans a larger area to fit within the bounding box defined by the coordinates [-3, 53, 3, 55].
const turf = require('@turf/turf');
const line = turf.lineString([
[-5, 52], [-5, 56], [5, 56], [5, 52]
]);
const bbox = [-3, 53, 3, 55];
const clipped = turf.bboxClip(line, bbox);
console.log(JSON.stringify(clipped));
Clip a MultiPolygon to a Bounding Box
This feature allows you to clip a MultiPolygon to a specified bounding box. The code sample demonstrates how to clip a MultiPolygon that spans a larger area to fit within the bounding box defined by the coordinates [-3, 53, 3, 55].
const turf = require('@turf/turf');
const multiPolygon = turf.multiPolygon([[
[[-5, 52], [-5, 56], [5, 56], [5, 52], [-5, 52]]
], [
[[-10, 50], [-10, 54], [0, 54], [0, 50], [-10, 50]]
]]);
const bbox = [-3, 53, 3, 55];
const clipped = turf.bboxClip(multiPolygon, bbox);
console.log(JSON.stringify(clipped));
The jsts (JavaScript Topology Suite) library offers a wide range of geospatial operations, including clipping geometries to a bounding box. While it provides more comprehensive geospatial processing capabilities, it is also more complex and has a steeper learning curve compared to @turf/bbox-clip.
Takes a Feature and a bbox and clips the feature to the bbox using lineclip. May result in degenerate edges when clipping Polygons.
feature
Feature<(LineString | MultiLineString | Polygon | MultiPolygon)> feature to clip to the bboxbbox
BBox extent in [minX, minY, maxX, maxY] ordervar bbox = [0, 0, 10, 10];
var poly = turf.polygon([[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]]);
var clipped = turf.bboxClip(poly, bbox);
//addToMap
var addToMap = [bbox, poly, clipped]
Returns Feature<(LineString | MultiLineString | Polygon | MultiPolygon)> clipped Feature
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.
Install this single module individually:
$ npm install @turf/bbox-clip
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf bbox-clip module
The npm package @turf/bbox-clip receives a total of 0 weekly downloads. As such, @turf/bbox-clip popularity was classified as not popular.
We found that @turf/bbox-clip demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.