Buffer

Trait Buffer 

Source
pub trait Buffer {
    type Scalar: BoolOpsNum + 'static;

    // Required method
    fn buffer_with_style(
        &self,
        style: BufferStyle<Self::Scalar>,
    ) -> MultiPolygon<Self::Scalar>;

    // Provided method
    fn buffer(&self, distance: Self::Scalar) -> MultiPolygon<Self::Scalar> { ... }
}
Expand description

Create a new geometry whose boundary is offset the specified distance from the input.

The buffer operation creates polygons which represent all points within a specified distance from the input geometry. For example, buffering a point creates a circle, buffering a line creates a “pill” shape, and buffering a polygon creates a larger polygon (or a smaller one if a negative distance is requested).

§Examples

Basic buffering with default style:

use geo::{Point, Buffer, MultiPolygon};

let point = Point::new(0.0, 0.0);
// Creates an approximated circle with radius 2.0
let buffered: MultiPolygon = point.buffer(2.0);

Default buffering rounds the point where geometries meet and where lines end. Use a custom style for more control:

use geo::{wkt, MultiPolygon, Buffer};
use geo::algorithm::buffer::{BufferStyle, LineCap, LineJoin};

let lines = wkt! {            
    MULTILINESTRING(
        (0. 0.,2. 0.,1. 2.),
        (0. -1.,2. 1.,3. 3.)
    )
};
let style = BufferStyle::new(0.5)
    .line_cap(LineCap::Square)
    .line_join(LineJoin::Miter(1.0));
let buffered: MultiPolygon = lines.buffer_with_style(style);

Required Associated Types§

Source

type Scalar: BoolOpsNum + 'static

Required Methods§

Source

fn buffer_with_style( &self, style: BufferStyle<Self::Scalar>, ) -> MultiPolygon<Self::Scalar>

Create a new geometry whose boundary is offset the specified distance from the input using the specific styling options where lines intersect (line joins) and end (end caps). For default (rounded) styling, see buffer.

This method allows control over the buffer appearance through the BufferStyle parameter.

§Arguments
  • style - A BufferStyle that specifies the distance, line caps, and line joins.
§Returns

A MultiPolygon representing the buffered geometry.

§Examples
use geo::{wkt, Buffer};
use geo::algorithm::buffer::{BufferStyle, LineCap, LineJoin};

let line_string = wkt! { LINESTRING (0. 0.,2. 0.,1. 2.) };
let style = BufferStyle::new(1.5)
    .line_cap(LineCap::Square)
    .line_join(LineJoin::Bevel);
let buffered = line_string.buffer_with_style(style);

Provided Methods§

Source

fn buffer(&self, distance: Self::Scalar) -> MultiPolygon<Self::Scalar>

Create a new geometry whose boundary is offset the specified distance from the input.

By default, buffering uses rounded joins and end caps. See buffer_with_style for more control.

§Arguments
  • distance - The buffer distance. Positive values create an outward buffer, negative values create an inward buffer (for polygons).
§Returns

A MultiPolygon representing the buffered geometry.

§Examples
use geo::{Point, Buffer, MultiPolygon};

let point = Point::new(5.0, 5.0);
let circle: MultiPolygon = point.buffer(3.0);

use geo::algorithm::Area;
// Creates an approximately circular polygon centered at (5, 5) with radius 30
assert_relative_eq!(circle.unsigned_area(), std::f64::consts::PI * 3.0f64.powi(2), epsilon = 2e-1);

Implementors§

Source§

impl<F: BoolOpsNum + 'static> Buffer for Geometry<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for GeometryCollection<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for Line<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for LineString<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for MultiLineString<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for MultiPoint<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for MultiPolygon<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for Point<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for Polygon<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for Rect<F>

Source§

impl<F: BoolOpsNum + 'static> Buffer for Triangle<F>