Atlaslog
Atlaslog / Turf.js / Tutorial / Length, area, center and bounding box
Turf.js · Tutorial

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.

Last verified 2026-11-03 · Turf.js 7.x · Cite this page
Key points
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
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Length, area, center and bounding box. https://www.jingweizhi.com/en/turf/tutorials/measurement.html (accessed 2026-11-03).