From 96734b3c024767ee15193d90ce4fb7db5497955b Mon Sep 17 00:00:00 2001 From: "s0wlz (Matthias Puchstein)" Date: Mon, 15 Dec 2025 21:51:39 +0100 Subject: [PATCH] Move setup/download helpers into scripts/ and update paths --- .gitignore | 3 --- AGENTS.md | 4 ++-- README.md | 9 +++++---- export_ortho_tiles.py | 2 +- scripts/dlscript_dop20.sh | 29 +++++++++++++++++++++++++++++ scripts/setup_dirs.sh | 27 +++++++++++++++++++++++++++ 6 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 scripts/dlscript_dop20.sh create mode 100644 scripts/setup_dirs.sh diff --git a/.gitignore b/.gitignore index 14e9f13..365d9b2 100644 --- a/.gitignore +++ b/.gitignore @@ -43,13 +43,10 @@ export_unity/buildings_obj/ raw/** !raw/dop20/ raw/dop20/** -!raw/dop20/dlscript.sh !raw/dop20/filelist.txt raw/dop20/jp2/** !raw/dop/ raw/dop/** -!raw/dop/dlscript.sh -!raw/dop/filelist.txt raw/dop/jp2/** archives/ diff --git a/AGENTS.md b/AGENTS.md index 5c5818f..1d4f648 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,9 +9,9 @@ ## Build, Test, and Development Commands - Create a venv: `uv venv && source .venv/bin/activate`. Install deps: `uv sync` (generates `uv.lock`). - If wheels fail, install system GDAL first (e.g., `brew install gdal` or `apt-get install gdal-bin libgdal-dev`), then rerun `uv sync`. -- Prepare the directory tree (raw/archives/work/exports): `bash setup_dirs.sh`. +- Prepare the directory tree (raw/archives/work/exports): `bash scripts/setup_dirs.sh`. - Heightmap export (rebuilds VRT if absent): `uv run python export_heightmaps.py`. -- Orthophoto export: `uv run python export_ortho_tiles.py` (requires JP2s under `raw/dop20/jp2/`; alt `raw/dop/jp2/` and legacy `raw_dop/jp2/` still work). +- Orthophoto export: `uv run python export_ortho_tiles.py` (requires JP2s under `raw/dop20/jp2/`; alt `raw/dop/jp2/` and legacy `raw_dop/jp2/` still work). Use `bash scripts/dlscript_dop20.sh` to fetch JP2/J2W/XML listed in `raw/dop20/filelist.txt`. - Refresh VRT manually if needed: `gdalbuildvrt work/dgm.vrt raw/dgm1/*.tif` (legacy: `raw_dgm1/*.tif`). - Inspect a result: `gdalinfo export_unity/height_png16/.png | head` to sanity-check bounds and scaling. - Expected warning: `Computed -srcwin ... falls partially outside source raster extent` means the DOP coverage is slightly smaller than the tile footprint; edge pixels will be filled with NoData/zeros. Add adjacent JP2s or shrink the requested window if you need to silence it. diff --git a/README.md b/README.md index 4e61c3d..ffaf937 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This repository converts DGM1 elevation tiles into Unity-ready 16-bit PNG height - Create a project venv: `uv venv && source .venv/bin/activate`. - Install dependencies from `pyproject.toml`: `uv sync` (generates `uv.lock`; warning-free with dependency-groups). - If wheels fail to resolve, ensure system GDAL is present (e.g., `brew install gdal` or `apt-get install gdal-bin libgdal-dev`), then rerun `uv sync`. -- Create the default directory tree (inputs/archives/outputs): `bash setup_dirs.sh`. +- Create the default directory tree (inputs/archives/outputs): `bash scripts/setup_dirs.sh`. ### Repository Layout - `raw/` — preferred working inputs (not versioned): `raw/dgm1/`, `raw/dop20/jp2/` (or `raw/dop/jp2/`), `raw/citygml/lod1/`, `raw/citygml/lod2/`. Legacy directories (`raw_dgm1/`, `raw_dop/`, `raw_3dgeb_lod1/`, `raw_3dgeb_lod2/`) are still honored by the scripts. @@ -27,11 +27,12 @@ This repository converts DGM1 elevation tiles into Unity-ready 16-bit PNG height ### Quick Start 1. Activate the uv venv (`source .venv/bin/activate`) or prefix commands with `uv run`. -2. Export Unity heightmaps and manifest (builds `work/dgm.vrt` automatically if missing): +2. Ensure directory tree exists: `bash scripts/setup_dirs.sh`. +3. Export Unity heightmaps and manifest (builds `work/dgm.vrt` automatically if missing): ```bash uv run python export_heightmaps.py ``` -3. Import the PNGs into Unity Terrains using `tile_index.csv` for placement and consistent height scaling (0–65535). +4. Import the PNGs into Unity Terrains using `tile_index.csv` for placement and consistent height scaling (0–65535). ### Key Commands - Refresh VRT: `gdalbuildvrt work/dgm.vrt raw/dgm1/*.tif` (legacy: `raw_dgm1/*.tif`) @@ -48,7 +49,7 @@ This repository converts DGM1 elevation tiles into Unity-ready 16-bit PNG height - Handoff to Unity: copy/sync `export_unity/height_png16/` and `export_unity/tile_index.csv` into `DTrierFlood/Assets/GeoData/` before running the Unity-side importer. Keep `OUT_RES` aligned with the importer’s expected resolution (currently 1025). ### Orthophotos (textures) -1. Ensure DOP JP2s are present in `raw/dop20/jp2/` (alt: `raw/dop/jp2/`, legacy: `raw_dop/jp2/`); use `raw/dop20/dlscript.sh` to fetch JP2/J2W/XML entries listed in `filelist.txt` (one URL per line). +1. Ensure DOP JP2s are present in `raw/dop20/jp2/` (alt: `raw/dop/jp2/`, legacy: `raw_dop/jp2/`); use `scripts/dlscript_dop20.sh` to fetch JP2/J2W/XML entries listed in `raw/dop20/filelist.txt` (one URL per line). 2. From `GeoData/`, run: ```bash uv run python export_ortho_tiles.py diff --git a/export_ortho_tiles.py b/export_ortho_tiles.py index 80c749a..487019c 100644 --- a/export_ortho_tiles.py +++ b/export_ortho_tiles.py @@ -53,7 +53,7 @@ def export_orthos(args: argparse.Namespace) -> int: jp2_paths = sorted(glob.glob(os.path.join(raw_ortho_dir, "*.jp2"))) if not jp2_paths: raise SystemExit( - f"No JP2 files found in {raw_ortho_dir}. Run raw/dop20/dlscript.sh (or raw/dop/dlscript.sh, legacy raw_dop/dlscript.sh) first." + f"No JP2 files found in {raw_ortho_dir}. Run scripts/dlscript_dop20.sh (or use the fallback layouts) first." ) build_vrt(args.vrt_path, jp2_paths) diff --git a/scripts/dlscript_dop20.sh b/scripts/dlscript_dop20.sh new file mode 100644 index 0000000..7412bfa --- /dev/null +++ b/scripts/dlscript_dop20.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Download DOP20 assets (JP2/J2W/XML) listed line-by-line in raw/dop20/filelist.txt. +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" +DOP_ROOT="$ROOT/raw/dop20" +LIST="${LIST:-$DOP_ROOT/filelist.txt}" +OUT="$DOP_ROOT/jp2" + +if [[ ! -f "$LIST" ]]; then + echo "Missing filelist: $LIST" >&2 + exit 1 +fi + +mkdir -p "$OUT" + +while IFS= read -r url; do + [[ -z "$url" || "$url" =~ ^# ]] && continue + fname="${url##*/}" + dest="$OUT/$fname" + if [[ -f "$dest" ]]; then + echo "Exists: $fname" + continue + fi + echo "Downloading $fname" + curl -fL "$url" -o "$dest" +done < "$LIST" + +echo "Done. Files in $OUT" diff --git a/scripts/setup_dirs.sh b/scripts/setup_dirs.sh new file mode 100644 index 0000000..84ac937 --- /dev/null +++ b/scripts/setup_dirs.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Create the default directory layout for GeoData inputs/outputs. +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" + +DIRS=( + "$ROOT/raw/dgm1" + "$ROOT/raw/dop20/jp2" + "$ROOT/raw/dop/jp2" + "$ROOT/raw/citygml/lod1" + "$ROOT/raw/citygml/lod2" + "$ROOT/archives/dgm1" + "$ROOT/archives/dop20" + "$ROOT/archives/citygml/lod1" + "$ROOT/archives/citygml/lod2" + "$ROOT/work" + "$ROOT/export_unity/height_png16" + "$ROOT/export_unity/ortho_jpg" +) + +for dir in "${DIRS[@]}"; do + mkdir -p "$dir" +done + +echo "Created default directories:" +printf ' - %s\n' "${DIRS[@]}"