geofileops.export_by_location#
- geofileops.export_by_location(input_to_select_from_path: str | os.PathLike[Any], input_to_compare_with_path: str | os.PathLike[Any], output_path: str | os.PathLike[Any], spatial_relations_query: str = 'intersects is True', min_area_intersect: float | None = None, area_inters_column_name: str | None = None, input1_layer: str | None = None, input1_columns: list[str] | None = None, input2_layer: str | None = None, output_layer: str | None = None, gridsize: float = 0.0, where_post: str | None = None, nb_parallel: int | None = None, batchsize: int = -1, subdivide_coords: int = 7500, force: bool = False) None#
Exports all features filtered by the specified spatial query.
All features in
input_to_select_from_paththat comply to thespatial_relations_querycompared with the features ininput_to_compare_with_pathare exported.The
spatial_relations_queryhas a specific format. For most cases can use the following “named spatial predicates”: contains, coveredby, covers, crosses, disjoint, equals, intersects, overlaps, touches and within. If you want even more control, you can also use “spatial masks” as defined by the DE-9IM model.Some examples of valid
spatial_relations_queryvalues:“touches is True or within is True”
“intersects is True and touches is False”
“(T*T***T** is True or 1*T***T** is True) and T*****FF* is False”
Alternative names:
QGIS: extract by location
- Parameters:
input_to_select_from_path (PathLike) – the 1st input file
input_to_compare_with_path (PathLike) – the 2nd input file
output_path (PathLike) – the file to write the result to
spatial_relations_query (str, optional) – a query that specifies the spatial relations to match between the 2 layers. Defaults to “intersects is True”.
min_area_intersect (float, optional) – minimum area of the intersection. Defaults to None.
area_inters_column_name (str, optional) – column name of the intersect area. If None, no area column is added. Defaults to None.
input1_layer (str, optional) – 1st input layer name. If None,
input_to_select_from_pathshould only contain 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) – 2nd input layer name. If None,
input_to_compare_with_pathshould contain only one layer. Defaults to None.input2_columns (List[str], optional) – NA.
output_layer (str, optional) – output layer name. If None, the
output_pathstem is used. Defaults to None.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 in the input to compare with layer will be subdivided to parts with about
subdivide_coordscoordinates during processing which can offer a large speed up for complex geometries. If 0, no subdividing is applied. Defaults to 7.500.force (bool, optional) – overwrite existing output file(s). Defaults to False.
See also
export_by_bounds(): export features that intersect with the bounds specifiedexport_by_distance(): export features that are within a certain distance of features of another layerexport_by_location(): export features that e.g. intersect with features of another layerjoin_by_location(): join features that e.g. intersect with features of another layer