# 判断是否包含(booleanContains)
npm install @turf/boolean-contains
Boolean-contains returns True if the second geometry is completely contained by the first geometry. The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a). Boolean-contains returns the exact opposite result of the @turf/boolean-within.
如果第二个几何图形完全包含在第一个几何图形中,则返回 True。两个几何图形的内部必须相交,次要图形的内部和边界(几何图形 b)不能与主要图形的外部(几何图形 a)相交。返回值与
@turf/boolean-within
完全相反的结果。注意:经过测试当几何1为面,几何2位线时,计算结果不准确。例如:
let result = turf.booleanContains( {"type":"Polygon","coordinates":[[[119.9833917617798,28.1637864112854],[119.8131036758423,28.005857944488525],[119.97103214263917,27.95779275894165],[120.11797428131105,28.00173807144165],[119.9833917617798,28.1637864112854]]]}, {"type":"LineString","coordinates":[[119.89412784576417,27.99924898147583],[119.86528873443605,27.975903034210205]]} ); //=ture 应该是false
参数
参数 | 类型 | 描述 |
---|---|---|
feature1 | Geometry|Feature | 外圈 GeoJSON |
feature2 | Geometry|Feature | 内圈 GeoJSON |
返回
boolean - true/false
示例
var line = turf.lineString([
[1, 1],
[1, 2],
[1, 3],
[1, 4],
]);
var point = turf.point([1, 2]);
turf.booleanContains(line, point);
//=true
基础用法
Copy
动态绘制
Copy