Shapely: parallel_offset和buffer无法正确关闭轮廓

创建于 2018-02-06  ·  4评论  ·  资料来源: Toblerity/Shapely

预期行为和实际行为。

有时,当使用parallel_offsetbuffer ,生成的轮廓未正确闭合。 轮廓未正确闭合的点总是看起来是轮廓的第一个/最后一个点。

以下是我最初在StackExchange上发布的问题。

重现此问题的步骤。

这是一个最小的工作示例,该示例使用parallel_offset生成不会闭合的轮廓。 使用buffer ,将创建圆角(尽管mitred样式)。
奇怪的是,在我更大的数据集中,还有其他非常相似的轮廓可以成功闭合。

import matplotlib.pyplot as plt
from shapely.geometry.polygon import LinearRing

def plot_line(ax, ob, color):
    x, y = ob.xy
    ax.plot(x, y, color=color, alpha=0.7, linewidth=3, 
            solid_capstyle='round', zorder=2)

polygon = [[-29.675, -30.675],
           [-28.4094, -29.4094],
           [-28.325, -29.325],
           [-28.325, -29.764],
           [-28.325, -29.7933],
           [-28.4587, -29.8274],
           [-28.4676, -29.8297],
           [-28.5956, -29.8814],
           [-28.6041, -29.8848],
           [-28.724, -29.953],
           [-28.732, -29.9576],
           [-28.8417, -30.0413],
           [-28.849, -30.0469],
           [-28.9466, -30.1445],
           [-28.9531, -30.151],
           [-29.0368, -30.2607],
           [-29.0424, -30.268],
           [-29.1106, -30.3879],
           [-29.1152, -30.3959],
           [-29.1669, -30.5239],
           [-29.1703, -30.5324],
           [-29.2044, -30.6661],
           [-29.2067, -30.675],
           [-29.6457, -30.675],
           [-29.675, -30.675]]

poly_line = LinearRing(polygon)
poly_line_offset = poly_line.parallel_offset(0.05, side="left", resolution=16, 
                                             join_style=2, mitre_limit=1)
# Alternative:
# poly_line_offset = poly_line.buffer(0.05, resolution=16, join_style=2, mitre_limit=1).exterior

fig = plt.figure()
ax = fig.add_subplot(111)
plot_line(ax, poly_line, "blue")
plot_line(ax, poly_line_offset, "green")
plt.show()

操作系统

Windows 7,Python 3.6.2

匀称的版本和出处

Shapely 1.6.3(从PyPI安装)

geos upstream bug

最有用的评论

@ doctor-ian这是一个有趣的应用程序,实际上使我的Python崩溃了。 我认为这里的GEOS库中有一个错误。 平行偏移不是为闭环设计的,但应该更优雅地失效。 另一方面,多边形的负缓冲区可以工作:

untitled

所有4条评论

@ doctor-ian这是一个有趣的应用程序,实际上使我的Python崩溃了。 我认为这里的GEOS库中有一个错误。 平行偏移不是为闭环设计的,但应该更优雅地失效。 另一方面,多边形的负缓冲区可以工作:

untitled

@sgillies我已经担心潜在的问题不在

我认为是个错误。

在C-API中, GEOSOffsetCurve_r被记录为仅接受LINESTRING。 如果我们也想接受LinearRings,则需要以某种方式添加该支持。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

dopplershift picture dopplershift  ·  3评论

LostFan123 picture LostFan123  ·  5评论

mromanie picture mromanie  ·  3评论

mikedh picture mikedh  ·  6评论

ispmarin picture ispmarin  ·  3评论