geofileops.clip#

geofileops.clip(input_path: Union[str, os.PathLike[Any]], clip_path: Union[str, os.PathLike[Any]], output_path: Union[str, os.PathLike[Any]], input_layer: Optional[str] = None, input_columns: Optional[List[str]] = None, clip_layer: Optional[str] = None, output_layer: Optional[str] = None, explodecollections: bool = False, gridsize: float = 0.0, where_post: Optional[str] = None, nb_parallel: int = -1, batchsize: int = -1, force: bool = False)#

Clip the input layer with the clip layer.

The resulting layer will contain the parts of the geometries in the input layer that overlap with the dissolved geometries in the clip layer.

Clarifications:
  • every row in the input layer will result in maximum one row in the output layer.

  • geometries in the input layer that overlap with multiple adjacent geometries in the clip layer won’t result in the input geometries getting split.

This is the result you can expect when clipping a polygon layer (yellow) with another polygon layer (purple):

Input

Clip result

Clip input

Clip result

Parameters:
  • input_path (PathLike) – The file to clip.

  • clip_path (PathLike) – The file with the geometries to clip with.

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

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

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

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

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

  • explodecollections (bool, optional) – True to convert all multi-geometries to singular ones after the dissolve. 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.

  • where_post (str, optional) – SQL filter to apply after all other processing, including e.g. explodecollections. It should be in sqlite syntax and spatialite reference 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.