geofileops.difference#
- geofileops.difference(input1_path: str | os.PathLike[Any], input2_path: str | os.PathLike[Any] | None, output_path: str | os.PathLike[Any], input1_layer: str | None = None, input1_columns: list[str] | None = None, input2_layer: str | None = None, output_layer: str | None = None, explodecollections: bool = False, gridsize: float = 0.0, where_post: str | None = None, nb_parallel: int | None = None, batchsize: int = -1, subdivide_coords: int = 2000, force: bool = False) None#
Calculate the difference of the input1 layer and input2 layer.
If
input2_pathis None, the 1st input layer is used for both inputs but interactions between the same rows in this layer will be ignored. The output will be the (pieces of) features in this layer that don’t have any intersections with other features in this layer.Remarks:
Every row in the input layer will result in maximum one row in the output layer.
The output will contain the columns from the 1st no columns from the 2nd layer. The attribute values wont’t be changed, so columns like area,… will have to be recalculated manually.
To speed up processing, complex input geometries are subdivided by default. For these geometries, the output geometries will contain extra collinear points where the subdividing occured. This behaviour can be controlled via the
subdivide_coordsparameter.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: erase
- Parameters:
input1_path (PathLike) – The file to remove/difference from.
input2_path (PathLike, optional) – The file with the geometries to remove from input1. If None, the 1st input layer is used for both inputs but interactions between the same rows in this layer will be ignored. The output will be the (pieces of) features in this layer that don’t have any intersections with other features in this layer.
output_path (PathLike) – the file to write the result to.
input1_layer (str, optional) – input layer name. If None,
input1_pathshould contain only 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 eg. to “fid_1”. Defaults to None.
input2_layer (str, optional) – input2 layer name. If None,
input2_pathshould contain only one layer. Defaults to None.output_layer (str, optional) – output layer name. If None, the
output_pathstem 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 | 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.subdivide_coords (int, optional) – the input geometries will be subdivided to parts with about
subdivide_coordscoordinates during processing which can offer a large speed up for complex geometries. Subdividing can result in extra collinear points being added to the boundaries of the output. If 0, no subdividing is applied. Defaults to 2000.force (bool, optional) – overwrite existing output file(s). Defaults to False.
See also
identity(): calculate the identity of two layersintersection(): calculate the intersection of two layerssymmetric_difference(): calculate the symmetric difference of two layersunion(): calculate the union of two layers