Buffering line with flat cap style using GeoPandas?

GeoPandas isn't passing through all arguments to the shapely buffer method. Instead you can use the standard pandas apply method to call buffer on each geometry individually, e.g.:

# Assumes that geometry will be the geometry column
capped_lines = df.geometry.apply(lambda g: g.buffer(100, cap_style=2))

Also, not that this returns a GeoPandas GeoSeries object, so if you need the attributes (and projection for that matter, though that may be an outstanding issue) you'll need to overwite the geometry column in the original GeoDataFrame.


GeoPandas now pass kwargs to shapely, so you can do below now:

gdf.geometry.to_crs("epsg:3857").buffer(10, cap_style=2)

PR: https://github.com/geopandas/geopandas/pull/535

Update: reason for change crs to 3857 is control on buffer radius in meter, else geopandas raise below warning:

UserWarning: Geometry is in a geographic CRS. Results from 'buffer' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.