#!/usr/bin/env python3
import sys
import math
from pyproj import Transformer

def main():
    if len(sys.argv) < 3:
        print("Nutzung: etrs89_to_utm32 <Lat> <Lon> [Höhe_m]")
        sys.exit(1)

    lat = float(sys.argv[1])
    lon = float(sys.argv[2])
    height = float(sys.argv[3]) if len(sys.argv) > 3 else 0.0

    # ETRS89 / WGS84 (EPSG:4326) zu UTM Zone 32N (EPSG:25832)
    transformer = Transformer.from_crs("EPSG:4326", "EPSG:25832", always_xy=True)
    easting_0, northing_0 = transformer.transform(lon, lat)

    # Höhenreduktionsfaktor (R_m ≈ 6371000 m)
    R_m = 6371000.0
    scale = (R_m + height) / R_m if height != 0 else 1.0

    # Reduzierte Koordinaten auf Geländehöhe
    # Mittlerer Meridian UTM Zone 32 ist 9° E (Ostwert-Offset 500.000 m)
    easting_h = 500000.0 + (easting_0 - 500000.0) * scale
    northing_h = northing_0 * scale

    print(f"ETRS89 / WGS84 zu UTM Zone 32N Konvertierung")
    print(f"--------------------------------------------")
    print(f"Eingabe Breitengrad (Lat): {lat:.7f} deg")
    print(f"Eingabe Laengegrad (Lon): {lon:.7f} deg")
    print(f"Eingabe Hoehe (h):        {height:.1f} m")
    print(f"--------------------------------------------")
    print(f"UTM Zone 32 Ostwert (Easting) : {easting_h:.3f} m")
    print(f"UTM Zone 32 Nordwert (Northing): {northing_h:.3f} m")

if __name__ == "__main__":
    main()
