geofileops.copy_layer#

geofileops.copy_layer(src: Union[str, PathLike[Any]], dst: Union[str, PathLike[Any]], src_layer: Optional[str] = None, dst_layer: Optional[str] = None, src_crs: Optional[Union[int, str]] = None, dst_crs: Optional[Union[int, str]] = None, columns: Optional[Iterable[str]] = None, where: Optional[str] = None, sql_stmt: Optional[str] = None, sql_dialect: Optional[Literal['SQLITE', 'OGRSQL']] = None, reproject: bool = False, explodecollections: bool = False, force_output_geometrytype: Optional[Union[GeometryType, str]] = None, create_spatial_index: Optional[bool] = True, preserve_fid: Optional[bool] = None, dst_dimensions: Optional[str] = None, options: dict = {}, append: bool = False, force: bool = False)#

Read a layer from a source file and write it to a new destination file.

Typically used to convert from one fileformat to another or to reproject.

The options parameter can be used to pass any type of options to GDAL in the following form:

{ “<option_type>.<option_name>”: <option_value> }

The option types can be any of the following:
  • LAYER_CREATION: layer creation option (lco)

  • DATASET_CREATION: dataset creation option (dsco)

  • INPUT_OPEN: input dataset open option (oo)

  • DESTINATION_OPEN: destination dataset open option (doo)

  • CONFIG: config option (config)

The options can be found in the GDAL vector driver documentation.

Parameters:
  • src (PathLike) – The source file path.

  • dst (PathLike) – The destination file path.

  • src_layer (str, optional) – The source layer. If None and there is only one layer in the src file, that layer is taken. Defaults to None.

  • dst_layer (str, optional) – The destination layer. If None, the file stem is taken as layer name. Defaults to None.

  • src_crs (Union[str, int], optional) – an epsg int or anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes an EPSG string (eg. “EPSG:4326”), a well known text (WKT) CRS definition,… Defaults to None.

  • dst_crs (Union[str, int], optional) – an epsg int or anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes an EPSG string (eg. “EPSG:4326”), a well known text (WKT) CRS definition,… Defaults to None.

  • columns (Iterable[str], optional) – The (non-geometry) columns to read will be returned in the order specified. If None, all standard columns are read. 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.

  • where (str, optional) – only append the rows from src that comply to the filter specified. Applied before explodecollections. Filter should be in sqlite SQL WHERE syntax and spatialite reference functions can be used. If where contains the {geometrycolumn} placeholder, it is filled out with the geometry column name of the src file. Defaults to None.

  • sql_stmt (str) – SQL statement to use. Only supported with “pyogrio” engine.

  • sql_dialect (str, optional) – SQL dialect used. Options are None, “SQLITE” or “OGRSQL”. If None, for data sources with explicit SQL support the statement is processed by the default SQL engine (e.g. for Geopackage and Spatialite this is “SQLITE”). For data sources without native SQL support (e.g. .shp), the “OGRSQL” dialect is the default. If the “SQLITE” dialect is specified, spatialite reference functions can also be used. Defaults to None.

  • reproject (bool, optional) – True to reproject while converting the file. Defaults to False.

  • explodecollections (bool, optional) – True to output only simple geometries. Defaults to False.

  • force_output_geometrytype (Union[GeometryType, str], optional) – Geometry type. to (try to) force the output to. Defaults to None.

  • create_spatial_index (bool, optional) – True to create a spatial index on the destination file/layer. If None, the default behaviour by gdal for that file type is respected. If the LAYER_CREATION.SPATIAL_INDEX parameter is specified in options, create_spatial_index is ignored. Defaults to True.

  • preserve_fid (bool, optional) – True to make an extra effort to preserve fid’s of the source layer to the destination layer. False not to do any effort. None to use the default behaviour of gdal, that already preserves in some cases. Some file formats don’t explicitly store the fid (e.g. shapefile), so they will never be able to preserve fids. Defaults to None.

  • dst_dimensions (str, optional) – Force the dimensions of the destination layer to the value specified. Valid values: “XY”, “XYZ”, “XYM” or “XYZM”. Defaults to None.

  • options (dict, optional) – options to pass to gdal.

  • append (bool, optional) – True to append to the output file if it exists. Defaults to False.

  • force (bool, optional) – overwrite existing output file(s) Defaults to False.