The unary_union() function in shapely.ops is more efficient than accumulating with union().
shapely.ops中的unary_union()函数比union()的效率更高。
(Source code, png, hires.png, pdf)
- shapely.ops.unary_union(geoms)
Returns a representation of the union of the given geometric objects.
返回给定几何对象的合并结果。
Areas of overlapping Polygons will get merged. LineStrings will get fully dissolved and noded. Duplicate Points will get merged.
重叠的多边形区域将被合并。 线将被完全溶解和节点化。重复的点将被合并。
>>> from shapely.ops import unary_union
>>> polygons = [Point(i, 0).buffer(0.7) for i in range(5)]
>>> unary_union(polygons)
<shapely.geometry.polygon.Polygon object at 0x...>
Because the union merges the areas of overlapping Polygons it can be used in an attempt to fix invalid MultiPolygons. As with the zero distance buffer()
trick, your mileage may vary when using this.
因为合并了重叠的多边形区域,所以该方法可以用来修复无效的多边形。与零距离buffer()操作的技巧一样,在使用这个方法时,依实际情况可能有差别。
>>> m = MultiPolygon(polygons)
>>> m.area
7.6845438018375516
>>> m.is_valid
False
>>> unary_union(m).area
6.6103013551167971
>>> unary_union(m).is_valid
True
- shapely.ops.cascaded_union(geoms)
Returns a representation of the union of the given geometric objects.
返回给定几何对象的合并结果。
Note |
In 1.8.0 shapely.ops.cascaded_union() is deprecated, as it was superseded by shapely.ops.unary_union() .在1.8.0中,shapely.ops.cascaded_union()已被废弃,因为它被shapely.ops.unary_union()取代了。 |