geofileops.to_file#
- geofileops.to_file(gdf: DataFrame | GeoDataFrame, path: str | PathLike[Any], layer: str | None = None, force_output_geometrytype: GeometryType | str | None = None, force_multitype: bool = False, append: bool = False, append_timeout_s: int = 600, index: bool | None = None, create_spatial_index: bool | None = None, **kwargs: object) None#
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 “pyogrio”, “pyogrio-arrow” and “fiona”. Default engine is “pyogrio-arrow”. You can force/disable the use of arrow by passing e.g. use_arrow=True.
- Parameters:
gdf (gpd.GeoDataFrame) – The GeoDataFrame to export to file.
path (Union[str,) – The file path to write to. GDAL vsi paths can be used for handlers with write support.
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 already exists. If it doesn’t exist yet, it is created. Defaults to False.
append_timeout_s (int, optional) – This parameter is deprecated and is ignored.
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 None.
**kwargs – All additional parameters will be passed on to the io-engine used (“pyogrio” or “fiona”).
- Raises:
ValueError – an invalid parameter value was passed.
RuntimeError – timeout was reached while trying to append data to path.