hydromt.data_catalog.drivers.PyogrioDriver#

pydantic model hydromt.data_catalog.drivers.PyogrioDriver[source]#

Driver for GeoDataFrame using the pyogrio library: pyogrio.

Supports reading and writing files supported by the OGR library, including geopackage, shapefile, geojson and flatgeobuf.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

name: ClassVar[str] = 'pyogrio'#
supports_writing: ClassVar[bool] = True#

“Whether the driver supports writing data.

SUPPORTED_EXTENSIONS: ClassVar[set[str]] = {'.fgb', '.geojson', '.gpkg', '.shp'}#

“Set of supported file extensions for this driver.

read(uris: list[str], *, handle_nodata: NoDataStrategy = NoDataStrategy.RAISE, metadata: SourceMetadata | None = None, mask: Any = None, variables: str | list[str] | None = None) GeoDataFrame[source]#

Read geospatial data using the pyogrio library into a GeoDataFrame.

Supports formats such as GeoPackage, Shapefile, GeoJSON, and FlatGeobuf. Optionally applies spatial filtering through a bounding box derived from a provided mask.

Parameters:
  • uris (list[str]) – List of URIs to read data from. Only one file is supported per read operation.

  • handle_nodata (NoDataStrategy, optional) – Strategy to handle missing or empty data. Default is NoDataStrategy.RAISE.

  • metadata (SourceMetadata | None, optional) – Optional metadata object describing the dataset source (e.g. CRS).

  • mask (Any, optional) – Optional geometry or GeoDataFrame used to spatially filter the data while reading.

  • variables (str | list[str] | None, optional) – Optional list of columns to load from the dataset.

Returns:

The loaded geospatial data.

Return type:

gpd.GeoDataFrame

Raises:
  • ValueError – If multiple URIs are provided.

  • IOError – If the source file contains no geometry column.

Warning

The metadata parameter is not used directly in this driver, but is included for consistency with the GeoDataFrameDriver interface.

write(path: Path | str, data: GeoDataFrame, *, write_kwargs: dict[str, Any] | None = None) Path[source]#

Write a GeoDataFrame to disk using the pyogrio library.

Supports writing to vector formats supported by the OGR library, including GeoPackage (.gpkg), Shapefile (.shp), GeoJSON (.geojson), and FlatGeobuf (.fgb). The file format is inferred from the file extension. If the extension is unsupported, it falls back to FlatGeobuf (.fgb).

Parameters:
  • path (Path | str) – Destination path or URI where the GeoDataFrame will be written. Supported extensions are .gpkg, .shp, .geojson, and .fgb.

  • data (gpd.GeoDataFrame) – The GeoDataFrame to write.

  • write_kwargs (dict[str, Any], optional) – Additional keyword arguments passed to pyogrio.write_dataframe. Default is None.

Returns:

The path where the GeoDataFrame was written.

Return type:

Path

Raises:

ValueError – If the file extension cannot be determined or writing fails.