# 判断是否在线内(booleanWithin)
> npm install @turf/boolean-within
Boolean-within returns true if the first geometry is completely within the second geometry. The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a) must not intersect the exterior of the secondary (geometry b). Boolean-within returns the exact opposite result of the @turf/boolean-contains.
接收两个任意类型的要素,判断第一个要素是否包含于第二个要素,即真子集。返回的值与@turf/boolean-contains 是完全相反的结果
注意:经过测试当几何1为面,几何2位线时,计算结果不准确。例如:
let result = turf.booleanWithin( {"type":"LineString","coordinates":[[120.0767755508423,28.10035753250122],[120.09600162506105,28.08937120437622],[120.11385440826417,28.079758167266846],[120.15230655670167,28.07838487625122]]}, {"type":"Polygon","coordinates":[[[119.87078189849855,28.107223987579346],[119.94905948638917,28.16352891921997],[120.16191959381105,28.18824815750122],[120.13857364654542,28.055038928985596],[120.10286808013917,27.99873399734497],[119.87764835357667,28.019333362579346],[119.87078189849855,28.107223987579346]]]} );
参数
参数 | 类型 | 描述 |
---|---|---|
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.booleanWithin(point, line);
//=true
基础用法
Copy
动态绘制
Copy