Spaces:
Sleeping
Sleeping
| # inspect_pierce_columns_v2.py | |
| # | |
| # A focused diagnostic script to inspect the columns of GIS layers. | |
| # VERSION 2: Adds 'ignore_geometry=True' to handle corrupt or non-standard | |
| # geometry without crashing, allowing us to see the attribute columns. | |
| from pathlib import Path | |
| import geopandas as gpd | |
| import fiona | |
| class CONFIG: | |
| SOURCE_DATA_DIR = Path('pierce_gis_data') | |
| # --- ACTION REQUIRED --- | |
| # List the layers you want to inspect. | |
| LAYERS_TO_INSPECT = [ | |
| 'Tax_Parcels', | |
| # Add other layer names here if you have them. | |
| ] | |
| def find_data_sources(source_dir: Path): | |
| """Finds all potential data sources (.gdb folders).""" | |
| return list(source_dir.glob('*.gdb')) | |
| def find_and_load_layer_attributes(gdb_paths: list[Path], layer_name: str): | |
| """ | |
| Finds a layer and loads ONLY its attribute columns, ignoring geometry. | |
| """ | |
| for gdb_path in gdb_paths: | |
| try: | |
| available_layers = [lyr.lower() for lyr in fiona.listlayers(gdb_path)] | |
| if layer_name.lower() in available_layers: | |
| print(f" -> Found in Geodatabase: {gdb_path.name}") | |
| # This is the critical change: | |
| df = gpd.read_file(gdb_path, layer=layer_name, ignore_geometry=True) | |
| return df | |
| except Exception as e: | |
| print(f" -> ERROR reading attributes from {gdb_path.name}: {e}") | |
| continue | |
| return None | |
| def run_inspection(): | |
| """Loads each specified layer's attributes and prints its columns.""" | |
| print(f"--- π Starting Column Inspection (Ignoring Geometry) π ---\n") | |
| gdb_paths = find_data_sources(CONFIG.SOURCE_DATA_DIR) | |
| if not gdb_paths: | |
| print(f"FATAL: No '.gdb' directories found in '{CONFIG.SOURCE_DATA_DIR}'.") | |
| return | |
| for layer_name in CONFIG.LAYERS_TO_INSPECT: | |
| print(f"--- Inspecting Attributes For Layer: '{layer_name}' ---") | |
| df = find_and_load_layer_attributes(gdb_paths, layer_name) | |
| if df is not None: | |
| print("Columns found:") | |
| for col in df.columns: | |
| print(f" -> {col}") | |
| else: | |
| print(f"Layer '{layer_name}' not found or attributes could not be read.") | |
| print("-" * 40 + "\n") | |
| print("--- β Inspection Complete β ---") | |
| print("Use this list of columns to configure the main builder script.") | |
| if __name__ == '__main__': | |
| run_inspection() |