turf.triangleGrid
What is turf.triangleGrid?
turf.triangleGrid covers a bounding box with a lattice of triangular polygons and returns them as a FeatureCollection<Polygon>. Each cellSide × cellSide square is filled with two triangles.
turf.triangleGrid(bbox, cellSide, options?) → FeatureCollection<Polygon>Options include:
units— units forcellSide(default'kilometers')mask— aPolygonorMultiPolygon; cells whose centre lies outside the mask are droppedproperties— properties attached to every cell
When would you use turf.triangleGrid?
Use turf.triangleGrid for scientific visualisation, finite-element-style simulations on a map, or when you need a ready-made triangulation to feed into shaders or custom interpolation. It is also a common aesthetic choice for stylised thematic maps.
For most spatial binning tasks, hex grids are preferable — triangular bins are less intuitive to read and their small area per cell can fragment data. Reach for triangleGrid when you specifically need triangles.
1const bbox = [-122.6, 37.6, -122.3, 37.9];
2const tris = turf.triangleGrid(bbox, 0.5, { units: 'kilometers' });FAQs
How do I install Turf.js to use this function?
Install npm install @turf/triangle-grid and import import { triangleGrid } from '@turf/triangle-grid', or use turf.triangleGrid via @turf/turf.
How many triangles does one cellSide produce?
Two triangles per cellSide × cellSide square. So a grid covering a 10×10 cellSide bbox yields roughly 200 triangles.
Can I restrict the grid to an arbitrary polygon?
Yes, via options.mask. Triangles whose centroid lies outside the mask are omitted, which is faster than post-filtering the full grid.
Do triangles in triangleGrid form a TIN?
Not a Delaunay TIN — they form a regular lattice. If you need a triangulation over scattered points (with z-values), use turf.tin instead.