Turf.jsTransformation

turf.bboxClip

What is turf.bboxClip?

turf.bboxClip trims a GeoJSON LineString, MultiLineString, Polygon, or MultiPolygon to a rectangular bounding box. It uses the classic Cohen-Sutherland line-clipping algorithm and is much faster than turf.intersect when your clipping mask is a simple axis-aligned box.

JavaScript
turf.bboxClip(feature, bbox) → Feature<Geometry>

When would you use turf.bboxClip?

Use turf.bboxClip to constrain features to a tile or viewport extent — perfect for on-the-fly tile generation on a Node.js server, or pre-cutting features to a map viewport before rendering. It is also a fast way to drop parts of a polyline that fall outside a region of interest without invoking full polygon intersection.

On MapLibre, pairing turf.bboxClip with the current map bounds lets you ship minimal GeoJSON to a map source as the user pans, reducing render cost for very large datasets.

Code
undefined

FAQs

When should I use turf.intersect instead?

When your clipping mask is a non-rectangular polygon. turf.bboxClip is specifically optimised for axis-aligned rectangles and will not work with arbitrary polygons.

Does it handle polygons with holes?

Yes — holes are clipped independently of the exterior ring. Be aware that holes extending outside the bbox are trimmed to the bbox edge, which may produce topological oddities in rare edge cases.

How do I install just bboxClip?

npm install @turf/bbox-clip. It depends on @turf/helpers. Small and self-contained.

What about MultiLineString or MultiPolygon?

Supported. Each part is clipped independently. Empty parts (entirely outside the bbox) are dropped from the result.