geofileops.to_file#

geofileops.to_file(gdf: Union[DataFrame, GeoDataFrame], path: Union[str, PathLike[Any]], layer: Optional[str] = None, force_output_geometrytype: Optional[Union[GeometryType, str]] = None, force_multitype: bool = False, append: bool = False, append_timeout_s: int = 600, index: Optional[bool] = None, create_spatial_index: Optional[bool] = True)#

Writes a pandas dataframe to file.

The fileformat is detected based on the filepath extension.

The underlying library used to write the file can be choosen using the “GFO_IO_ENGINE” environment variable. Possible values are “fiona” and “pyogrio”. Default engine is “pyogrio”.

Parameters:
  • gdf (gpd.GeoDataFrame) – The GeoDataFrame to export to file.

  • path (Union[str,) – The file path to write to.

  • layer (str, optional) – The layer to read. If no layer is specified, reads the only layer in the file or throws an Exception.

  • force_output_geometrytype (Union[GeometryType, str], optional) –

    Geometry type to (try to) force the output to. Defaults to None. Mark: compared to other functions in gfo with this parameter, the behaviour here is limited to the following:

    • for empty input gdf’s, a standard geometry type (eg. Polygon,…) can be used to force the geometry column to be of that type.

    • if force_output_geometrytype is a MULTI type, parameter force_multitype becomes True.

  • force_multitype (bool, optional) – force the geometry type to a multitype for file types that require one geometrytype per layer. Defaults to False.

  • append (bool, optional) – True to append to the file/layer if it exists already. If it doesn’t exist yet, it is created. Defaults to False.

  • append_timeout_s (int, optional) – The maximum timeout to wait when the output file is already being written to by another process. Defaults to 600.

  • index (bool, optional) – If True, write index into one or more columns (for MultiIndex). 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. Defaults to None.

  • create_spatial_index (bool, optional) – True to force creation of spatial index, False to avoid creation. None leads to the default behaviour of gdal. Defaults to True.

Raises:
  • ValueError – an invalid parameter value was passed.

  • RuntimeError – timeout was reached while trying to append data to path.