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:
ProtocolProtocol 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.
- write(gdf, cloud_path, driver=None, schema=None, index=None, **kwargs)[source]#
Write the GeoDataFrame to the destination.
- Parameters:
- Raises:
ConnectionError – If the write operation fails due to network issues.
PermissionError – If access is denied.
- Return type: