Source code for shapelib.core.cloud.handlers.remote_spatialite_handler

"""Remote handler for SpatiaLite files using download."""

import tempfile
from pathlib import Path
from typing import Any

import geopandas as gpd

from shapelib.core.cloud.handlers.remote_handler import RemoteGeoFileHandler
from shapelib.factories.cloud_registry import register_cloud_handler


[docs] @register_cloud_handler(".sqlite") class RemoteSpatialiteHandler(RemoteGeoFileHandler): """ Handler for remote SpatiaLite files using download. SpatiaLite (SQLite-based) requires full file access for proper operation, so this handler downloads the file before reading. Attributes ---------- driver : str GDAL driver name: "SQLite". extension : str File extension: ".sqlite". Examples -------- >>> from shapelib import read_file >>> polygons = read_file("https://example.com/data.sqlite", layer="regions") Big-O ----- O(n) with full download required. """ driver: str = "SQLite" extension: str = ".sqlite"
[docs] def load_data(self, **kwargs: Any) -> gpd.GeoDataFrame: """ Load SpatiaLite data by downloading to temporary location. Parameters ---------- **kwargs : Any Additional arguments, including 'layer' for multi-layer files. Returns ------- gpd.GeoDataFrame The loaded geospatial data. """ from shapelib.factories.geo_cloud_factory import GeoCloudFactory with tempfile.TemporaryDirectory() as temp_dir: filename = Path(self.cloud_path.path).name temp_path = Path(temp_dir) / filename GeoCloudFactory.download_file(self.cloud_path, temp_path) return gpd.read_file(temp_path, **kwargs)