I am still struggling to grasp the difference between df.geometry.buffer and df.geometry.scale.

They can both be used to increase the size of a polygon but how are they different?

While in df.geometry.scale(xfact=1.01, yfact=1.01, zfact=1.01, origin='center') we know how much we could increase the size from the origin but in buffer it is unclear to me. For example, how much does df.geometry.buffer(0.001) increase the polygon? how can I check the final result?

Can someone clarify?

  • 1
    One scale the geometry by a factor (and can use different scale on each axis) while the other expend the feature by a fixed distance (as the distance is in the CRS unit this probably shouldn't be directly used with feature on a geographic CRS)
    – J.R
    Commented Feb 23, 2023 at 11:38

1 Answer 1

import geopandas as gpd
import shapely
import matplotlib.pyplot as plt

geoms = ["Polygon ((716228 7200069, 716072 7198883, 717168 7198760, 716228 7200069))",
         "Polygon ((714718 7200461, 713185 7199633, 714617 7200136, 713868 7199342, 714875 7200270, 714718 7200461))",
         "LineString (713487 7197585, 713610 7198659, 713968 7197541, 714192 7198547)"]
geoms = [shapely.wkt.loads(x) for x in geoms]

df = gpd.GeoDataFrame(geometry=geoms, crs=3006)

fig, ax = plt.subplots(figsize=(15, 15))
df.plot(ax=ax, color="blue")

When you buffer you get a polygon with "all points within a given distance of each geometric object." Imagine walking around the feature always at a fixed distance from it.

for distance in range(50,250,50):
    df.buffer(distance).plot(ax=ax, alpha=0.2)

enter image description here

My coordinate system have meters as units so buffer(50) means buffer with 50 meters.

When you scale the entire shape is enlarged or smallen. It is like you are zooming in or out, the shape is not changed, the corners stay the same etc.

for scale in range(11, 15, 1):
    df.scale(xfact=scale/10, yfact=scale/10).plot(ax=ax, alpha=0.1, color="green")

The units are factors in x, y, z dimensions. 1.5 means scale 150 %.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.