.buffer() while keeping original shape #2044
Unanswered
dorianherle
asked this question in
Q&A
Replies: 1 comment
-
I cannot reproduce your output. I assume you meant to take a "negative" offset and the from shapely.geometry import Polygon
# original polygon definition
original_poly = Polygon([(0, 0), (2, 1), (5, 1), (5, 2), (2, 2), (0, 2)])
# Apply dilation then erosion to round the corners
original_poly = original_poly.buffer(0.25).buffer(-0.5).buffer(0.25)
# compute offset polygon
offset_poly = original_poly.buffer(-0.5, resolution=16, join_style=1)
# plot result
from shapely.plotting import plot_polygon
plot_polygon(original_poly, add_points=False, alpha=0.7)
plot_polygon(offset_poly, add_points=False, color="k", alpha=0.7) that now gives To your original question about preserving the rounding: by default, this is actually preserved. You can notice that when reducing the buffer distance, for example from -0.5 to -0.15 gives the figure below: It's just that with the buffer distance of 0.5, this rounding is almost not noticeable anymore because of the erosion (and the requirement to keep the distance to the original border equal) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My question is also posted here:
https://stackoverflow.com/questions/78187566/how-to-offset-a-shaply-polygon-without-chnaging-corner-shape
I have the issue that I cannot buffer a shaply polygon such that the corner/shape stays the same. Here is my issue. Compare the buffered and original polygon:
It should keep the rounded corners...
Here is the code
Beta Was this translation helpful? Give feedback.
All reactions