Reputation: 965
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...
This is the code:
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
import geopandas as gpd
from matplotlib.lines import Line2D # Import for custom legend
# 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_poy = original_poly.buffer(0.5, resolution=16, join_style=1)
## PLOT
# Create GeoSeries from the polygons
original_poly_gseries = gpd.GeoSeries([original_poly])
offseted_poly_gseries = gpd.GeoSeries([offseted_polygon])
# Plotting
fig, ax = plt.subplots()
# Improved color palette and adjusted alpha for better visualization
original_poly_gseries.plot(ax=ax, color='#1f77b4', alpha=0.7) # A nice shade of blue
offseted_poly_gseries.plot(ax=ax, color='k', alpha=0.7) # A complementary shade of orange
# Creating custom legends with updated colors
legend_elements = [
Line2D([0], [0], color='#1f77b4', lw=4, label='Original Polygon'),
Line2D([0], [0], color='k', lw=4, label='Offset Polygon'),
]
# Placing the legend outside the plot
ax.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(1, 1))
plt.show()
Upvotes: 1
Views: 147