geofileops.dissolve_within_distance#

geofileops.dissolve_within_distance(input_path: str | os.PathLike[Any], output_path: str | os.PathLike[Any], distance: float, gridsize: float, close_internal_gaps: bool = False, input_layer: str | None = None, output_layer: str | None = None, nb_parallel: int | None = None, batchsize: int = -1, force: bool = False) None#

Dissolve geometries that are within the distance specified.

The output layer will contain the dissolved geometries where all gaps between the input geometries up to distance are closed.

Remarks:

  • Only tested on polygon input.

  • Gaps between the individual polygons of multipolygon input features will also be closed.

  • The polygons in the output file are exploded to simple geometries.

  • No attributes from the input layer are retained.

  • If close_internal_gaps is False, the default, a gridsize > 0 (E.g. 0.000001) should be specified, otherwise some input boundary gaps could still be closed due to rounding side effects.

  • Starting from geofileops 0.11.0, sliver polygons are removed from the output by default. Polygons are considered slivers if they are narrower than a certain tolerance. By default this tolerance is 0.001 CRS units if the CRS of the input layers is a projected CRS, 1e-7 if it is a geographic CRS. More information + information how to change this default tolerance can be found here: options.set_sliver_tolerance.

Alternative names:

  • ArcMap: aggregate_polygons (similar functionality)

  • Keywords: merge, dissolve, aggregate, snap, close gaps, union

Parameters:
  • input_path (PathLike) – the input file.

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

  • distance (float) – the maximum distance between geometries to be dissolved.

  • 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. If close_boundary_gaps is False, the default, a gridsize > 0 (E.g. 0.000001) should be specified, otherwise some boundary gaps in the input geometries could still be closed due to rounding side effects.

  • close_internal_gaps (bool, optional) – also close gaps, strips or holes in the input geometries that are narrower than the distance specified. E.g. small holes, narrow strips starting at the boundary,… Defaults to False.

  • input_layer (str, optional) – input layer name. If None, input_path should contain only one layer. Defaults to None.

  • output_layer (str, optional) – output layer name. If None, the output_path stem is used. Defaults to None.

  • nb_parallel (int | None, optional) – the number of parallel workers to use. If None, the preference set in the nb_parallel configuration option is used, which defaults to the number of CPU cores available. For more information, see options.set_nb_parallel(). Defaults to None.

  • 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.

See also