Atlaslog
Atlaslog / Turf.js / Tutorial / Geometry operations: intersect, union and difference
Turf.js · Tutorial

Geometry operations: intersect, union and difference

Quick answer

This tutorial covers polygon set operations: intersect for the shared area, union for the merged footprint, and difference for subtracting one polygon from another. It explains that intersect returns null when polygons only touch or are disjoint, why ring direction and self-intersections break topology, how cleanCoords and sliver filtering tidy results, and that attributes are not merged automatically. You will be able to run overlay analysis safely.

Last verified 2026-11-03 · Turf.js 7.x · Cite this page
Key points
Example
var a = turf.polygon([[[116.35, 39.86], [116.45, 39.86], [116.45, 39.94],
                       [116.35, 39.94], [116.35, 39.86]]]);

var b = turf.polygon([[[116.40, 39.90], [116.50, 39.90], [116.50, 39.98],
                       [116.40, 39.98], [116.40, 39.90]]]);

var inter = turf.intersect(a, b);
console.log(inter.geometry.type);            // Polygon
console.log(turf.area(inter) / 1e6);         // 平方公里

var merged = turf.union(a, b);
console.log(merged.geometry.type);           // Polygon,相邻时为单面

var rest = turf.difference(a, b);
console.log(turf.area(rest) / 1e6);
var inter = turf.intersect(a, b);
var areaKm2 = inter ? turf.area(inter) / 1e6 : 0;
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). Geometry operations: intersect, union and difference. https://www.jingweizhi.com/en/turf/tutorials/geometry-ops.html (accessed 2026-11-03).