Simplify, smooth and dissolve
Quick answer
This tutorial covers appearance-changing operations: turf.simplify with a tolerance in coordinate units and highQuality control, bezierSpline smoothing via resolution and sharpness, dissolve merging adjacent polygons that share a property, and convex versus concave hulls with maxEdge. It notes that these edits are irreversible and affect area and perimeter. You will be able to shrink payloads and produce smoother outlines.
Key points
- Set simplify tolerance in coordinate units, where 0.001 degrees is roughly 100 meters.
- Enable highQuality: true on turf.simplify for display lines that must not self-intersect.
- Call turf.dissolve(fc, { propertyName: 'zone' }) to merge adjacent polygons sharing that value.
Example
var track = turf.lineString([/* 几千个顶点 */]);
console.log('原始顶点', track.geometry.coordinates.length);
var coarse = turf.simplify(track, {
tolerance: 0.001, // 约 100 米
highQuality: true // 更接近原始形状,代价是更慢
});
console.log('简化后', coarse.geometry.coordinates.length);
var rough = turf.simplify(track, { tolerance: 0.01 });
console.log('更粗', rough.geometry.coordinates.length);var smooth = turf.bezierSpline(track, {
resolution: 20000, // 采样间隔,值越小点越密
sharpness: 0.85 // 0 到 1,越大越贴近原折线
});
console.log(turf.length(smooth, { units: 'kilometers' }).toFixed(3));
Notes
- Computing area after simplify reports a changed value, so measure before simplifying.
- Faces that only look adjacent fail to dissolve until cleanCoords or snapping removes the gaps.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Simplify, smooth and dissolve. https://www.jingweizhi.com/en/turf/tutorials/simplify-smooth.html (accessed 2026-11-03).