turf.tin
What is turf.tin?
turf.tin computes a Delaunay-based Triangulated Irregular Network (TIN) over a FeatureCollection<Point>. It returns a FeatureCollection<Polygon> where every polygon is a triangle, and each triangle carries the vertex z-values under properties a, b, c.
turf.tin(points, z?) → FeatureCollection<Polygon>Parameters:
points— input point collectionz— optional property name on each point whose value becomes the triangle's a/b/c
When would you use turf.tin?
Use turf.tin when you have scattered 3D data (elevation, temperature, rainfall) and you want a lightweight surface model that you can interpolate inside (via turf.planepoint), render as shaded triangles, or pass to a downstream client-side renderer.
TINs are well suited to data that is naturally irregular — survey points, weather stations, sensor readings. They preserve the original points exactly (every input becomes a triangle corner), unlike interpolation onto a regular grid.
1const triangles = turf.tin(stations, 'elevation');
2map.getSource('tin').setData(triangles);FAQs
How do I install Turf.js to use this function?
Install npm install @turf/tin and import import { tin } from '@turf/tin'. The umbrella bundle exposes turf.tin.
What happens if I have duplicate input points?
Duplicate coordinates can cause the triangulation to fail or produce degenerate triangles. Deduplicate your input before calling — keep one representative point per location and, if necessary, average the z-values.
How do I read the z-value at a non-vertex location?
Find the triangle containing your query point with turf.booleanPointInPolygon, then call turf.planepoint(point, triangle) to barycentrically interpolate across the triangle's plane.
When should I use a grid-based interpolation instead?
Use turf.interpolate when you need a raster-like surface for contouring (turf.isolines, turf.isobands) or equal-resolution analysis. Use turf.tin when you want to preserve original sample locations and keep triangular polygons as analysis units.