geofileops.intersection#

geofileops.intersection(input1_path: Union[str, os.PathLike[Any]], input2_path: Optional[Union[str, os.PathLike[Any]]], output_path: Union[str, os.PathLike[Any]], input1_layer: Optional[str] = None, input1_columns: Optional[list[str]] = None, input1_columns_prefix: str = 'l1_', input2_layer: Optional[str] = None, input2_columns: Optional[list[str]] = None, input2_columns_prefix: str = 'l2_', 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)#

Calculates the pairwise intersection of the two input layers.

Notes

  • The result will contain the attribute columns from both input layers. The attribute values wont’t be changed, so columns like area,… will have to be recalculated manually if this is wanted.

  • If input2_path is None, the 1st input layer is used for both inputs but intersections between the same rows in this layer will be omitted from the result.

Alternative names:
  • GeoPandas: overlay(how=”intersection”)

Parameters:
  • input1_path (PathLike) – the 1st input file

  • input2_path (PathLike) – the 2nd input file. If None, the 1st input layer is used for both inputs but intersections between the same rows in this layer will be omitted from the result.

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

  • input1_layer (str, optional) – input layer name. Optional if the file only contains one layer. Defaults to None.

  • input1_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 even if input1_columns_prefix is “”, eg. to “fid_1”. Defaults to None.

  • input1_columns_prefix (str, optional) – prefix to use in the column aliases. Defaults to “l1_”.

  • input2_layer (str, optional) – input layer name. Optional if the file only contains one layer. Defaults to None.

  • input2_columns (List[str], optional) – columns to select. If None is specified, all columns are selected. As explained for input1_columns, it is also possible to specify “fid”. Defaults to None.

  • input2_columns_prefix (str, optional) – prefix to use in the column aliases. Defaults to “l2_”.

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

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