code: def _to_file(
      df,
      filename,
      driver=None,
      schema=None,
      index=None,
      mode="w",
      crs=None,
      engine=None,
      **kwargs,
  ):
      """
      Write this GeoDataFrame to an OGR data source
  
      A dictionary of supported OGR providers is available via:
      >>> import fiona
      >>> fiona.supported_drivers  # doctest: +SKIP
  
      .. note::
  
          GeoPandas currently defaults to use Fiona as the engine in ``to_file``.
          However, GeoPandas 1.0 will switch to use pyogrio as the default engine, since
          pyogrio can provide a significant speedup compared to Fiona. We recommend to
          already install pyogrio and specify the engine by using the ``engine`` keyword
          (``df.to_file(..., engine="pyogrio")``), or by setting the default for
          the ``engine`` keyword globally with::
  
              geopandas.options.io_engine = "pyogrio"
  
      Parameters
      ----------
      df : GeoDataFrame to be written
      filename : string
          File path or file handle to write to. The path may specify a
          GDAL VSI scheme.
      driver : string, default None
          The OGR format driver used to write the vector file.
          If not specified, it attempts to infer it from the file extension.
          If no extension is specified, it saves ESRI Shapefile to a folder.
      schema : dict, default None
          If specified, the schema dictionary is passed to Fiona to
          better control how the file is written. If None, GeoPandas
          will determine the schema based on each column's dtype.
          Not supported for the "pyogrio" engine.
      index : bool, default None
          If True, write index into one or more columns (for MultiIndex).
          Default None writes the index into one or more columns only if
          the index is named, is a MultiIndex, or has a non-integer data
          type. If False, no index is written.
  
          .. versionadded:: 0.7
              Previously the index was not written.
      mode : string, default 'w'
          The write mode, 'w' to overwrite the existing file and 'a' to append;
          when using the pyogrio engine, you can also pass ``append=True``.
          Not all drivers support appending. For the fiona engine, the drivers
          that support appending are listed in fiona.supported_drivers or
          https://github.com/Toblerity/Fiona/blob/master/fiona/drvsupport.py.
          For the pyogrio engine, you should be able to use any driver that
          is available in your installation of GDAL that supports append
          capability; see the specific driver entry at
          https://gdal.org/drivers/vector/index.html for more information.
      crs : pyproj.CRS, default None
          If specified, the CRS is passed to Fiona to
          better control how the file is written. If None, GeoPandas
          will determine the crs based on crs df attribute.
          The value can be anything accepted
          by :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
          such as an authority string (eg "EPSG:4326") or a WKT string.
      engine : str, "fiona" or "pyogrio"
          The underlying library that is used to write the file. Currently, the
          supported options are "fiona" and "pyogrio". Defaults to "fiona" if
          installed, otherwise tries "pyogrio".
      **kwargs :
          Keyword args to be passed to the engine, and can be used to write
          to multi-layer data, store data within archives (zip files), etc.
          In case of the "fiona" engine, the keyword arguments are passed to
          fiona.open`. For more information on possible keywords, type:
          ``import fiona; help(fiona.open)``. In case of the "pyogrio" engine,
          the keyword arguments are passed to `pyogrio.write_dataframe`.
  
      Notes
      -----
      The format drivers will attempt to detect the encoding of your data, but
      may fail. In this case, the proper encoding can be specified explicitly
      by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
      """
      engine = _check_engine(engine, "'to_file' method")
  
      filename = _expand_user(filename)
  
      if index is None:
          # Determine if index attribute(s) should be saved to file
          # (only if they are named or are non-integer)
          index = list(df.index.names) != [
              None
          ] or not is_integer_dtype(df.index.dtype)
      if index:
          df = df.reset_index(drop=False)
  
      if driver is None:
          driver = _detect_driver(filename)
  
      if driver == "ESRI Shapefile" and any(
          len(c) > 10 for c in df.columns.tolist()
      ):
          warnings.warn(
              "Column names longer than 10 characters will be truncated when saved to "
              "ESRI Shapefile.",
              stacklevel=3,
          )
  
      if (df.dtypes == "geometry").sum() > 1:
          raise ValueError(
              "GeoDataFrame contains multiple geometry columns but GeoDataFrame.to_file "
              "supports only a single geometry column. Use a GeoDataFrame.to_parquet or "
              "GeoDataFrame.to_feather, drop additional geometry columns or convert them "
              "to a supported format like a well-known text (WKT) using "
              "`GeoSeries.to_wkt()`.",
          )
  
      if mode not in ("w", "a"):
          raise ValueError(
              f"'mode' should be one of 'w' or 'a', got '{mode}' instead"
          )
  
      if engine == "fiona":
          _to_file_fiona(
              df, filename, driver, schema, crs, mode, **kwargs
          )
      elif engine == "pyogrio":
          _to_file_pyogrio(
              df, filename, driver, schema, crs, mode, **kwargs
          )
      else:
          raise ValueError(f"unknown engine '{engine}'")
  
imports: import os
  from packaging.version import Version
  from pathlib import Path
  import warnings
  import numpy
  import pandas
  from pandas.api.types import is_integer_dtype
  import pyproj
  from shapely.geometry import mapping
  from shapely.geometry.base import BaseGeometry
  from geopandas import GeoDataFrame, GeoSeries
  from urllib.parse import urlparse
  from urllib.parse import uses_netloc, uses_params, uses_relative
  import urllib.request
  from geopandas._compat import PANDAS_GE_20
label_desc: Use image node_id 15 for calling a global function with example usage: _to_file(df, filename, driver, schema, index, mode, crs, engine) without return types