from pathlib import Path import geopandas as gpd import pandas as pd import rasterio def _is_raster(path: str) -> bool: return Path(path).suffix.lower() in {".tif", ".tiff", ".nc", ".asc"} def get_spatial_metadata(path: str) -> dict: if _is_raster(path): with rasterio.open(path) as src: return { "type": "raster", "crs": str(src.crs) if src.crs else "", "bounds": list(src.bounds), "width": src.width, "height": src.height, "count": src.count, "resolution": list(src.res), "driver": src.driver, "dtypes": list(src.dtypes), } vector = gpd.read_file(path) return { "type": "vector", "crs": str(vector.crs) if vector.crs else "", "feature_count": int(len(vector)), "columns": list(vector.columns), "geometry_types": sorted(vector.geometry.geom_type.dropna().unique().tolist()), "bounds": list(vector.total_bounds), } def get_attribute_table(path: str, n: int = 25) -> pd.DataFrame: vector = gpd.read_file(path) return pd.DataFrame(vector.drop(columns="geometry").head(n)) def raster_quality_report(path: str) -> pd.DataFrame: with rasterio.open(path) as src: checks = [ {"check": "has_crs", "value": bool(src.crs)}, {"check": "has_bounds", "value": True}, {"check": "band_count", "value": src.count}, {"check": "resolution", "value": f"{src.res[0]} x {src.res[1]}"}, {"check": "driver", "value": src.driver}, ] return pd.DataFrame(checks)