Length, area, center and bounding box
Quick answer
This tutorial explains the measurement core: turf.length for cumulative line length, turf.distance for two points, and turf.area, which always returns square meters and takes no units option. It compares center, centroid, centerOfMass and pointOnFeature for label placement, and shows bbox plus bboxPolygon for extents. You will be able to report believable distances and areas.
Key points
- Use turf.length(route, { units: 'kilometers' }) rather than passing a coordinate array to turf.distance.
- Place labels with turf.centerOfMass or turf.pointOnFeature so they fall inside irregular polygons.
- Convert bbox output with turf.bboxPolygon for clipping or coarse filtering.
Example
var route = turf.lineString([
[116.391263, 39.907359],
[116.407000, 39.899000],
[116.430000, 39.910000]
]);
var km = turf.length(route, { units: 'kilometers' });
var mi = turf.length(route, { units: 'miles' });
var deg = turf.length(route, { units: 'degrees' });
console.log(km.toFixed(3), mi.toFixed(3), deg.toFixed(3));var plot = turf.polygon([[
[116.380, 39.900],
[116.400, 39.900],
[116.400, 39.915],
[116.380, 39.915],
[116.380, 39.900]
]]);
var m2 = turf.area(plot);
var km2 = m2 / 1e6;
var ha = m2 / 1e4;
var mu = m2 / 666.6667; // 1 亩 ≈ 666.67 平方米
console.log(m2.toFixed(1), km2.toFixed(4), ha.toFixed(2), mu.toFixed(2));
Notes
- Using units: 'degrees' and treating the result as meters is off by about five orders of magnitude.
- Self-intersecting rings skew or even negate the spherical area, so run turf.kinks first.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Length, area, center and bounding box. https://www.jingweizhi.com/en/turf/tutorials/measurement.html (accessed 2026-11-03).