首页 / Turf.js / API 文档
booleanDisjoint
先看结论
两个几何完全没有公共点时返回真,是 booleanIntersects 的逻辑取反。
turf.booleanDisjoint(feature1, feature2, options?) → boolean
参数
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
feature1 | Geometry | Feature | — | 第一个几何 |
feature2 | Geometry | Feature | — | 第二个几何 |
options.ignoreSelfIntersections | boolean | true | 忽略输入几何自身的自相交 |
注意这个选项的默认值是 true,
而 booleanIntersects 的同名选项默认是 false。
两函数并不严格互为取反,除非把选项对齐。
示例
var parcel = turf.polygon([[
[116.38, 39.90],
[116.42, 39.90],
[116.42, 39.94],
[116.38, 39.94],
[116.38, 39.90]
]]);
var point = turf.point([116.50, 39.92]);
console.log(turf.booleanDisjoint(parcel, point)); // true
console.log(turf.booleanDisjoint(parcel, parcel)); // false
批量粗筛
var candidates = buildings.features.filter(function (b) {
return !turf.booleanDisjoint(b, roadBuffer, {
ignoreSelfIntersections: false
});
});
先用 booleanDisjoint 过滤掉明显无关的要素,
再对剩下的记录做 intersect 或面积计算,能省掉大量几何求交。
先看包围盒更快
function quickDisjoint(a, b) {
var ba = turf.bbox(a);
var bb = turf.bbox(b);
return ba[2] < bb[0] || bb[2] < ba[0] ||
ba[3] < bb[1] || bb[3] < ba[1];
}
包围盒分离时几何必然分离,这一步只做四次比较。 大数据量场景下,先跑这个判断可以把完整几何运算的次数降到很低。
与 touches 的区别
| 关系 | booleanDisjoint | booleanTouches |
|---|---|---|
| 完全分离 | true | false |
| 仅边界接触 | false | true |
| 部分重叠 | false | false |
浮点误差会让相邻面「不分离」。 两块理论上共边的多边形,顶点小数位不完全一致时, 交集计算可能出现极细的缝隙或重叠。拓扑清洗后再判断, 或给判断加一个极小的缓冲区吸收误差。
经纬志(2026)。《booleanDisjoint》。https://www.jingweizhi.com/turf/api/boolean-disjoint.html(访问日期 2026-11-03)。