geofileops.buffer#

geofileops.buffer(input_path: Union[str, os.PathLike[Any]], output_path: Union[str, os.PathLike[Any]], distance: float, quadrantsegments: int = 5, endcap_style: BufferEndCapStyle = BufferEndCapStyle.ROUND, join_style: BufferJoinStyle = BufferJoinStyle.ROUND, mitre_limit: float = 5.0, single_sided: bool = False, input_layer: Optional[str] = None, output_layer: Optional[str] = None, columns: Optional[List[str]] = None, explodecollections: bool = False, gridsize: float = 0.0, keep_empty_geoms: Optional[bool] = None, where_post: Optional[str] = None, nb_parallel: int = -1, batchsize: int = -1, force: bool = False)#

Applies a buffer operation on geometry column of the input file.

The result is written to the output file specified.

If explodecollections is False and the input and output file type is GeoPackage, the fid will be preserved. In other cases this will typically not be the case.

Parameters:
  • input_path (PathLike) – the input file

  • output_path (PathLike) – the file to write the result to

  • distance (float) – the buffer size to apply. In projected coordinate systems this is typically in meter, in geodetic systems this is typically in degrees.

  • quadrantsegments (int) – the number of points a quadrant needs to be approximated with for rounded styles. Defaults to 5.

  • endcap_style (BufferEndCapStyle, optional) –

    buffer style to use for a point or the end points of a line. Defaults to ROUND.

    • ROUND: for points and lines the ends are buffered rounded.

    • FLAT: a point stays a point, a buffered line will end flat at the end points

    • SQUARE: a point becomes a square, a buffered line will end flat at the end points, but elongated by distance

  • join_style (BufferJoinStyle, optional) –

    buffer style to use for corners in a line or a polygon boundary. Defaults to ROUND.

    • ROUND: corners in the result are rounded

    • MITRE: corners in the result are sharp

    • BEVEL: are flattened

  • mitre_limit (float, optional) – in case of join_style MITRE, if the spiky result for a sharp angle becomes longer than this ratio limit, it is “beveled” using this maximum ratio. Defaults to 5.0.

  • single_sided (bool, optional) – only one side of the line is buffered, if distance is negative, the left side, if distance is positive, the right hand side. Only relevant for line geometries. Defaults to False.

  • input_layer (str, optional) – input layer name. Optional if the input file only contains one layer.

  • output_layer (str, optional) – input layer name. Optional if the input file only contains one layer.

  • columns (List[str], optional) – list of columns to retain. If None, all standard columns are retained. In addition to standard columns, it is also possible to specify “fid”, a unique index available in all input files. Note that the “fid” will be aliased eg. to “fid_1”. Defaults to None.

  • explodecollections (bool, optional) – True to output only simple geometries. Defaults to False.

  • gridsize (float, optional) – the size of the grid the coordinates of the ouput will be rounded to. Eg. 0.001 to keep 3 decimals. Value 0.0 doesn’t change the precision. Defaults to 0.0.

  • keep_empty_geoms (bool, optional) – True to keep rows with empty/null geometries in the output. Defaults to False.

  • where_post (str, optional) – SQL filter to apply after all other processing, including e.g. explodecollections. It should be in sqlite syntax and spatialite functions can be used. Defaults to None.

  • nb_parallel (int, optional) – the number of parallel processes to use. Defaults to -1: use all available CPUs.

  • batchsize (int, optional) – indicative number of rows to process per batch. A smaller batch size, possibly in combination with a smaller nb_parallel, will reduce the memory usage. Defaults to -1: (try to) determine optimal size automatically.

  • force (bool, optional) – overwrite existing output file(s). Defaults to False.

Notes

Using the different buffer style option parameters you can control how the buffer is created:

  • quadrantsegments (int)

5 (default)

2

1

Buffer with quadrantsegments=5

Buffer with quadrantsegments=2

Buffer with quadrantsegments=1

  • endcap_style (BufferEndCapStyle)

ROUND (default)

FLAT

SQUARE

Buffer with endcap_style=BufferEndCapStyle.ROUND (default)

Buffer with endcap_style=BufferEndCapStyle.FLAT

Buffer with endcap_style=BufferEndCapStyle.SQUARE

  • join_style (BufferJoinStyle)

ROUND (default)

MITRE

BEVEL

Buffer with joinstyle=BufferJoinStyle.ROUND (default)

Buffer with joinstyle=BufferJoinStyle.MITRE

Buffer with joinstyle=BufferJoinStyle.BEVEL

  • mitre (float)

5.0 (default)

2.5

1.0

Buffer with mitre=5.0

Buffer with mitre=2.5

Buffer with mitre=1.0