获取不同距离的线串周围的缓冲区

问题描述 投票:0回答:1

给定一个线串和一个同样长的距离(标量)列表,如何获得一条位于原始折线左侧(或右侧)的新折线,并具有列表中相应位置指定的偏移量?本质上是 shapely.offset_curve() 会做的事情,但偏移距离不固定。

enter image description here

numpy geometry shapely
1个回答
0
投票

一种方法是单独缓冲顶点/点,计算每个连接的缓冲顶点/点对的凸包,然后计算这些凸包的溶解并集。

import shapely

line = shapely.LineString([(0,0), (5, 6), (8, -4), (16, 9)])
buffer_sizes = [1, 2, 3, 4]

points = [shapely.Point(coords) for coords in line.coords]

buffered_points = [
   point.buffer(s) for s, point in zip(buffered_points, points)
]

convex_hulls = []
for i in range(len(buffered_points)-1):
    convex_hulls.append(
        shapely.convex_hull(
            shapely.union(
                buffered_points[i], 
                buffered_points[i+1]
            )
        )
    )

buffered_line = shapely.union_all(convex_hulls)

offset_lines = shapely.difference(
    shapely.difference(buffered_line.exterior, buffered_points[0]),
    buffered_points[-1]
)

可能有一种更优雅和更有效的方法,但它似乎可以解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.