【问题标题】:How to use Shapely for subtracting two polygons如何使用 Shapely 减去两个多边形
【发布时间】:2020-09-07 19:41:54
【问题描述】:

我不太确定如何解释,但我有 2 个多边形,Polygon1 和 Polygon2。这些多边形相互重叠。如何在没有来自 Polygon1 的 P 的情况下使用 Shapely 获得 Polygon2。

【问题讨论】:

  • 所以你想在减去重叠区域后得到Polygon2的余数?
  • @Torxed 是的,没错。

标签: python shapely set-difference


【解决方案1】:

您正在寻找difference。在 Shapely 中,您可以使用 difference 方法或简单地从另一个多边形中减去*一个多边形来计算它:

from shapely.geometry import Polygon

polygon1 = Polygon([(0.5, -0.866025), (1, 0), (0.5, 0.866025), (-0.5, 0.866025), (-1, 0), (-0.5, -0.866025)])
polygon2 = Polygon([(1, -0.866025), (1.866025, 0), (1, 0.866025), (0.133975, 0)])

difference = polygon2.difference(polygon1)  # or difference = polygon2 - polygon1

有关更多集合论方法,请参阅docs。


*此功能未记录。请参阅 GitHub 上的问题:Document set-like properties。

【讨论】:

    猜你喜欢
    • 2022-11-15
    • 2023-02-17
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多