turf.js difference计算面差
Finds the difference between two polygons by clipping the second polygon from the first.
如图示计算的是属于面1不属于面2的部分;千万不要理解错了。
Arguments参数
Argument | Type | Description |
---|---|---|
polygon1 | Feature <(Polygon、MultiPolygon)> | input Polygon feature |
polygon2 | Feature <(Polygon、MultiPolygon)> | Polygon feature to difference from polygon1 |
翻译如下
参数 | 类型 | 描述 |
---|---|---|
面1 | 特征对象 <(面、多面)> | 输入面 |
面2 | 特征对象 <(面、多面)> | 相对于面1用于做差的面2 |
Returns返回值
(Feature <(Polygon|MultiPolygon)>|null) - a Polygon or MultiPolygon feature showing the area of polygon1 excluding the area of polygon2 (if empty returns null )
一个Polygon或MultiPolygon要素,显示了polygon1的面积,不包括polygon2的面积(如果empty返回null)
Example例子
var polygon1 = turf.polygon([[
[128, -26],
[141, -26],
[141, -21],
[128, -21],
[128, -26]
]], {
"fill": "#F00",
"fill-opacity": 0.1
});
var polygon2 = turf.polygon([[
[126, -28],
[140, -28],
[140, -20],
[126, -20],
[126, -28]
]], {
"fill": "#00F",
"fill-opacity": 0.1
});
var difference = turf.difference(polygon1, polygon2);