Im trying to scale one shape to a larger one, like this:
I have an example here
poly_context = {'type': 'MULTIPOLYGON',
'coordinates': [[[[1, 2], [2, 1], [4, 3], [3, 4]]]]}
poly_shape = shapely.geometry.asShape(poly_context)
If your polygon is not convex, the scale
method may not give you the desired output. For example:
import geopandas as gpd
from shapely import Polygon
from shapely import affinity
vertices = [(0, 0), (1, 1), (2, 0.5), (2.5, 2), (0.5, 2.5)]
# Create the polygon
polygon = Polygon(vertices)
scaled_polygon = affinity.scale(polygon, xfact=1.2, yfact=1.2)
gdf = gpd.GeoDataFrame({'geometry': [scaled_polygon, polygon]})
gdf.plot(column='geometry')
So, maybe the desired method should be buffer
instead of scale
.
Example:
buffered_polygon = polygon.buffer(0.2, join_style=2)
gdf = gpd.GeoDataFrame({'geometry': [buffered_polygon, polygon]})
gdf.plot(column='geometry')
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