added export scripts for ortho and buildings

This commit is contained in:
2025-12-14 02:56:33 +01:00
parent da16f66d30
commit 22b5dd4fa5
4 changed files with 245 additions and 6 deletions

View File

@@ -18,6 +18,20 @@ os.makedirs(OUT_DIR, exist_ok=True)
gdal.UseExceptions()
def build_dgm_vrt_if_needed():
"""Build the DGM VRT automatically when missing."""
if os.path.exists(VRT_PATH):
return
tif_paths = sorted(glob.glob(os.path.join(RAW_DIR, "*.tif")))
if not tif_paths:
raise SystemExit(f"No TIFFs found in {RAW_DIR}; cannot build {VRT_PATH}.")
print(f"Building {VRT_PATH} from {len(tif_paths)} GeoTIFFs...")
try:
gdal.BuildVRT(VRT_PATH, tif_paths)
except RuntimeError as exc:
raise SystemExit(f"Could not build {VRT_PATH}: {exc}") from exc
def open_dataset(path, purpose):
"""Open a dataset and fail fast with context."""
try:
@@ -57,7 +71,8 @@ def cleanup_aux_files():
print(f"Cleanup removed {removed} temporary files/sidecars.")
ds = open_dataset(VRT_PATH, f"Could not open {VRT_PATH}. Did you run gdalbuildvrt?")
build_dgm_vrt_if_needed()
ds = open_dataset(VRT_PATH, f"Could not open {VRT_PATH} after attempting to build it.")
band = ds.GetRasterBand(1)