문제

How do I modify an existing Polygon? For a start, I'd like to add a Point to its exterior.

poly = Polygon([(0, 0), (1, 1), (1, 0)])

I was looking for something like this:

poly.append_at(idx=3, Point(1, -1))

But I cannot find any even similar methods for doing this.

도움이 되었습니까?

해결책

It doesn't make sense to add or remove points from a Polygon's exterior, because you'd want to recalculate poly.area, poly.length, etc. anyway. Instead, create a new Polygon instance from the old polygon's coordinates:

coords = poly.exterior.coords[:]
coords[1] = (2.0, 6.0) # coordinate to change

new_poly = Polygon(coords)

Note that this doesn't account for points in poly.interior.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top