shapelib.core.ports package#

Ports (interfaces) for the domain layer.

Submodules#

shapelib.core.ports.file_writer_port module#

Port (Protocol) for file writing strategies.

class shapelib.core.ports.file_writer_port.FileWriterStrategy(*args, **kwargs)[source]#

Bases: Protocol

Protocol defining the interface for file writing strategies.

This protocol follows the Strategy pattern, allowing different implementations for saving geospatial data to various destinations (local filesystem, cloud storage, etc.).

Implementations must provide: - supports(): Check if this strategy handles the given path - write(): Perform the actual write operation

Examples

Implementing a custom writer:

>>> class MyCloudWriter:
...     def supports(self, cloud_path: CloudPath) -> bool:
...         return cloud_path.scheme == "mycloud"
...
...     def write(
...         self,
...         gdf: gpd.GeoDataFrame,
...         cloud_path: CloudPath,
...         **kwargs: Any,
...     ) -> None:
...         # Upload to MyCloud
...         pass

Notes

This protocol enables Clean Architecture by allowing the Domain (BaseShapes) to depend on an abstraction rather than concrete infrastructure implementations.

supports(cloud_path)[source]#

Check if this strategy supports the given path.

Parameters:

cloud_path (CloudPath) – The parsed destination path.

Returns:

True if this strategy can handle the path.

Return type:

bool

write(gdf, cloud_path, driver=None, schema=None, index=None, **kwargs)[source]#

Write the GeoDataFrame to the destination.

Parameters:
  • gdf (GeoDataFrame) – The GeoDataFrame to save.

  • cloud_path (CloudPath) – The parsed destination path.

  • driver (str | None) – The file driver (e.g., ‘FlatGeobuf’).

  • schema (Any | None) – The schema definition.

  • index (Any | None) – Whether to write the index.

  • **kwargs (Any) – Additional arguments.

Raises:
Return type:

None