MEASUREMENT
COORDINATE MUTATION
TRANSFORMATION
FEATURE_CONVERSION
MISC
HELPER
RANDOM
GRIDS
AGGREGATION
META
ASSERTIONS
BOOLEANS
UNIT CONVERSION
DATA
JOINS
CLASSIFICATION

booleanOverlap

booleanOverlap是Turf中的一个函数,用于检查两个多边形是否有重叠部分,并返回重叠部分的几何图形。

语法

turf.booleanOverlap(poly1, poly2)

参数

  • poly1:(必需)代表第一个多边形的Polygon或MultiPolygon。
  • poly2:(必需)代表第二个多边形的Polygon或MultiPolygon。

返回值

返回两个多边形的重叠部分的Polygon或MultiPolygon几何图形。如果两个多边形没有重叠部分,则返回null

示例

var poly1 = turf.polygon([[
  [-77.035279,38.889484],
  [-77.033412,38.889961],
  [-77.033412,38.889961],
  [-77.035279,38.889484]
]]);
var poly2 = turf.polygon([[
  [-77.038843,38.889598],
  [-77.037813,38.88986],
  [-77.037656,38.889188],
  [-77.038843,38.889598]
]]);
var overlap = turf.booleanOverlap(poly1, poly2);

console.log(overlap);

输出:

{
  "type": "Polygon",
  "coordinates": [
    [
      [-77.035279,38.889484],
      [-77.033412,38.889961],
      [-77.037813,38.88986],
      [-77.038843,38.889598],
      [-77.037656,38.889188],
      [-77.035279,38.889484]
    ]
  ]
}

异常

如果给定的输入多边形是无效的(不是一个Polygon或MultiPolygon),则会抛出一个错误。