Turf.jsInterpolation

turf.planepoint

What is turf.planepoint?

turf.planepoint takes a point and a triangular polygon and returns the z-value at the point's location by linearly interpolating across the triangle's plane. The triangle's three vertices supply the z-values either through the polygon's a, b, c properties or through the vertices' third coordinate.

JavaScript
turf.planepoint(point, triangle) → number

Parameters:

  • point — a Feature<Point> or Point geometry inside the triangle
  • triangle — a Feature<Polygon> whose outer ring has exactly three unique vertices

When would you use turf.planepoint?

turf.planepoint is the companion to turf.tin: given a terrain triangulation, use turf.tin to build triangles with z-values, then call turf.planepoint at any user-clicked location to read the interpolated elevation without a DEM lookup.

It is equally useful for any scalar field — temperature, rainfall, intensity — once you have a TIN representation. In Web Mercator visualisations, be aware that planepoint interpolates in 2D planar coordinates; for spherical-grade accuracy, project first.

JavaScript
1const triangles = turf.tin(stations, 'temperature');
2map.on('click', e => {
3  const pt = turf.point([e.lngLat.lng, e.lngLat.lat]);
4  const tri = triangles.features.find(t => turf.booleanPointInPolygon(pt, t));
5  if (tri) {
6    console.log('T =', turf.planepoint(pt, tri));
7  }
8});

FAQs

How do I install Turf.js to use this function?

Install with npm install @turf/planepoint and import import { planepoint } from '@turf/planepoint'. It is also on @turf/turf as turf.planepoint.

What happens if my point is outside the triangle?

The function still returns a number (an extrapolation along the plane), but the result is geometrically meaningless. Always filter with turf.booleanPointInPolygon before calling.

How do I put z-values on the triangle?

Two options: set properties.a, properties.b, properties.c to the three vertex values in ring order, or pass triangles whose vertex coordinates already include a third element (z). turf.tin produces triangles with the a, b, c property convention.

Does turf.planepoint interpolate on the sphere?

No. It treats lng/lat as a flat plane and performs barycentric interpolation. Over small triangles (tens of kilometres) the error is negligible; over continental-scale triangles you should reproject to an equal-area system first.