0017a2f88821f15e8a0ce6f017d7a4500ea06c87
GeoData Heightmap Export
This repository converts DGM1 elevation tiles into Unity-ready 16-bit PNG heightmaps and a placement manifest. It relies on GDAL for mosaicking, resampling, and scaling to UInt16 ranges Unity expects.
Prerequisites
- GDAL installed with Python bindings (
osgeoimportable). - Python 3.9+ available on PATH.
- DGM1 source tiles placed under
raw/dgm1/asdgm1_<utm_zone>_<easting>_<northing>.tifwith matching.tfwfiles. - Raw inputs (
raw/dop20/,raw/citygml/lod1/,raw/citygml/lod2/) are kept out of git; keep them locally or document how to fetch/regenerate.
Environment setup (uv)
- Create a project venv:
uv venv && source .venv/bin/activate. - Install dependencies from
pyproject.toml:uv sync(generatesuv.lock). - If wheels fail to resolve, ensure system GDAL is present (e.g.,
brew install gdalorapt-get install gdal-bin libgdal-dev), then rerunuv sync. - Create the default directory tree and config:
uv run python geodata_to_unity.py --setup(orbash scripts/setup_dirs.shfor directories only).
Repository Layout
raw/— working inputs (not versioned):raw/dgm1/,raw/dop20/jp2/,raw/citygml/lod1/,raw/citygml/lod2/.archive/— offline storage for untouched downloads (e.g., zipped DOP/CityGML tiles, dop20 filelist).work/— intermediates such asdgm.vrtand_tmp.tiffiles; safe to delete/regenerate.export_unity/height_png16/— final 16-bit PNG heightmaps for Unity import.export_unity/tile_index.csv— manifest mapping tile IDs to world bounds and global min/max used for scaling.export_unity/ortho_jpg/— cropped orthophoto tiles aligned to the terrain grid (JPEG + worldfiles).geodata_to_unity.py— main CLI (usesgeodata_pipeline/library modules).scripts/— helpers to create the directory tree and fetch DOP20 inputs.geodata_config.json— generated config (seegeodata_config.example.jsonfor defaults).AGENTS.md— contributor guide.
Quick Start
- Activate the uv venv (
source .venv/bin/activate) or prefix commands withuv run. - Initialize config + directories:
uv run python geodata_to_unity.py --setup. - Export assets (builds VRTs automatically if missing):
uv run python geodata_to_unity.py --export all # heightmaps only: uv run python geodata_to_unity.py --export heightmap # textures only: uv run python geodata_to_unity.py --export textures - Import the PNGs into Unity Terrains using
tile_index.csvfor placement and consistent height scaling (0–65535).
Key Commands
- Refresh VRT:
gdalbuildvrt work/dgm.vrt raw/dgm1/*.tif - Run export pipeline:
uv run python geodata_to_unity.py --export all - Inspect an output tile:
gdalinfo export_unity/height_png16/<tile>.png | head - Override config paths: use
--config <path>,--raw-dgm1-path <dir>,--raw-dop20-path <dir>. - Use archives to populate raws:
uv run python geodata_to_unity.py --use-archive --export all(unzipsarchive/*and copies dop20 filelist).
Workflow Notes
- The pipeline computes a global min/max from the VRT to scale all tiles consistently; adjust
heightmap.out_resorheightmap.resampleingeodata_config.jsonif your AOI or target resolution changes. _tmp.tiffiles inwork/are transient; you can deletework/to force a clean rebuild.- Keep file names stable to avoid churn in Unity scenes; re-exports overwrite in place.
- Large raw datasets are intentionally excluded from version control—document download sources or scripts instead of committing data.
- Additional inputs: download helper lives in
scripts/dlscript_dop20.shand pulls JP2/J2W/XML orthophotos listed inraw/dop20/filelist.txt(one URL per line);archive/can hold zipped 3D building tiles for future use. - Handoff to Unity: copy/sync
export_unity/height_png16/andexport_unity/tile_index.csvintoDTrierFlood/Assets/GeoData/before running the Unity-side importer. Keepheightmap.out_resaligned with the importer’s expected resolution (currently 1025).
Orthophotos (textures)
- Ensure DOP JP2s are present in
raw/dop20/jp2/; usescripts/dlscript_dop20.shto fetch JP2/J2W/XML entries listed inraw/dop20/filelist.txt(one URL per line). - From
GeoData/, run:This buildsuv run python geodata_to_unity.py --export textureswork/dop.vrtif missing and writesexport_unity/ortho_jpg/<tile>.jpg+.jgwaligned totile_index.csv.- If you see
Computed -srcwin ... falls partially outside source raster extentwarnings, 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 avoid the warning.
- If you see
Buildings
The building export pipeline is temporarily disabled while we choose a mesh conversion approach (GDAL lacks a native OBJ writer). CityGML LoD2 sources remain in raw/citygml/lod2/ locally (ignored in git); consider CityGML→glTF/OBJ tools (e.g., citygml-tools + cityjson2gltf) for future integration.
Description
Languages
Python
66%
C#
26.4%
Shell
6%
Batchfile
1.6%