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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.