pygeoops.buffer_by_m#
- pygeoops.buffer_by_m(geometry, quad_segs: int = 8) BaseGeometry | ndarray[tuple[Any, ...], dtype[BaseGeometry]] | GeoSeries | None#
Calculates a variable width buffer for a geometry.
The buffer distance at each vertex is determined by the M value of that vertex, or the Z value if M is not available.
If a distance is zero, the resulting buffer will taper towards the original point. If the input is a LineString, this means the result will be a MultiPolygon where the parts touch at that point.
If a distance is negative or NaN, the resulting buffer will omit that point from treatment entirely. If the input is a LineString, this means the result will be a MultiPolygon with disjoint parts.
Support for Polygon input is experimental, feedback welcome.
Example output (grey: original line, blue: buffer):
(
Source code,png,hires.png,pdf)
Alternative name: variable width buffer.
Added in version 0.6.0.
- Parameters:
geometry (geometry, GeoSeries or arraylike) – a geometry, GeoSeries or arraylike.
quad_segs (int, optional) – The number of segments used to approximate a quarter circle. Defaults to 8.
- Returns:
- the buffer for each of the input
geometries.
- Return type:
geometry, GeoSeries or array_like
Examples
An example of buffering a single LineString with M values:
import pygeoops import shapely line = shapely.LineString([[0, 6, 1], [0, 0, 2], [10, 0, 2], [13, 5, 4]]) buffer_geom = pygeoops.buffer_by_m(line)
An example where the M values still need to be added to the LineString:
import pygeoops import shapely line = shapely.LineString([[0, 6], [0, 0], [10, 0], [13, 5]]) distances = [1, 2, 2, 4] line_with_m = shapely.LineString( [[x, y, m] for (x, y), m in zip(line.coords, distances)] ) buffer_geom = pygeoops.buffer_by_m(line_with_m)
An example of buffering a GeoDataFrame with LineStrings with M values:
import geopandas as gpd import pygeoops import shapely lines_gdf = gpd.GeoDataFrame( geometry=[ shapely.LineString([[0, 6, 1], [0, 0, 2], [10, 0, 2], [13, 5, 4]]), shapely.LineString([[0, 6, 1], [0, 0, 2], [10, 0, 2], [13, 5, 4]]), ], ) buffer_geoms = lines_gdf.copy() buffer_geoms.geometry = pygeoops.buffer_by_m(lines_gdf.geometry)