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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With