zusammenfügen 13.1.
This commit is contained in:
@@ -2,6 +2,10 @@ import sympy as sp
|
||||
from sympy.algebras.quaternion import Quaternion
|
||||
import Datenbank
|
||||
from itertools import combinations
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
from pyproj import CRS, Transformer, datadir
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Transformationen:
|
||||
@@ -280,3 +284,121 @@ class Transformationen:
|
||||
])
|
||||
return dict_transformiert
|
||||
|
||||
def utm_to_XYZ(self, pfad_tif_quasigeoidundolation, liste_utm):
|
||||
pfad_gcg_tif = Path(pfad_tif_quasigeoidundolation)
|
||||
pfad_gcg_tif_proj = pfad_gcg_tif.with_name("de_bkg_gcg2016.tif")
|
||||
|
||||
if (not pfad_gcg_tif_proj.exists()) or (pfad_gcg_tif_proj.stat().st_size != pfad_gcg_tif.stat().st_size):
|
||||
shutil.copy2(pfad_gcg_tif, pfad_gcg_tif_proj)
|
||||
|
||||
datadir.append_data_dir(str(pfad_gcg_tif.parent))
|
||||
|
||||
utm_epsg = 25832
|
||||
crs_src = CRS.from_user_input(f"EPSG:{utm_epsg}+EPSG:7837") # ETRS89/DREF91 + DHHN2016
|
||||
crs_dst = CRS.from_epsg(4936) # ETRS89 geozentrisch (ECEF)
|
||||
|
||||
tr_best = Transformer.from_crs(
|
||||
crs_src,
|
||||
crs_dst,
|
||||
always_xy=True,
|
||||
allow_ballpark=False,
|
||||
)
|
||||
|
||||
dict_geozentrisch_kartesisch = {}
|
||||
for Punktnummer, E, N, Normalhoehe in liste_utm:
|
||||
X, Y, Z = tr_best.transform(E, N, Normalhoehe)
|
||||
dict_geozentrisch_kartesisch[Punktnummer] = sp.Matrix([X, Y, Z])
|
||||
|
||||
# geographisch 3D + zeta
|
||||
#crs_geog3d = CRS.from_epsg(4937) # ETRS89 (lon, lat, h)
|
||||
#tr_h = Transformer.from_crs(
|
||||
# crs_src,
|
||||
# crs_geog3d,
|
||||
# always_xy=True,
|
||||
# allow_ballpark=False,
|
||||
#)
|
||||
|
||||
#lon, lat, h = tr_h.transform(E, N, H)
|
||||
#print("lon/lat/h:", lon, lat, h)
|
||||
#print("zeta (h-H):", h - H)
|
||||
|
||||
return dict_geozentrisch_kartesisch
|
||||
|
||||
def ecef_to_utm(
|
||||
self,
|
||||
dict_koordinaten: dict,
|
||||
pfad_gcg_tif: str | Path | None = None,
|
||||
zone: int = 32,
|
||||
):
|
||||
|
||||
if pfad_gcg_tif is not None:
|
||||
pfad_gcg_tif = Path(pfad_gcg_tif).resolve()
|
||||
if not pfad_gcg_tif.exists():
|
||||
raise FileNotFoundError(f"Quasigeoid-Datei nicht gefunden: {pfad_gcg_tif}")
|
||||
|
||||
pfad_proj_grid = pfad_gcg_tif.with_name("de_bkg_gcg2016.tif")
|
||||
if (
|
||||
not pfad_proj_grid.exists()
|
||||
or pfad_proj_grid.stat().st_size != pfad_gcg_tif.stat().st_size
|
||||
):
|
||||
shutil.copy2(pfad_gcg_tif, pfad_proj_grid)
|
||||
|
||||
datadir.append_data_dir(str(pfad_proj_grid.parent))
|
||||
|
||||
crs_src = CRS.from_epsg(4936) # ETRS89 geocentric (ECEF)
|
||||
|
||||
# Ziel-CRS: ETRS89 / UTM Zone 32/33 + DHHN2016 Normalhöhe
|
||||
# EPSG:25832/25833 = ETRS89 / UTM; EPSG:7837 = DHHN2016 height
|
||||
utm_epsg = 25800 + zone # 25832 oder 25833
|
||||
crs_dst = CRS.from_user_input(f"EPSG:{utm_epsg}+EPSG:7837")
|
||||
|
||||
tr = Transformer.from_crs(
|
||||
crs_src,
|
||||
crs_dst,
|
||||
always_xy=True,
|
||||
allow_ballpark=False,
|
||||
)
|
||||
|
||||
dict_koordinaten_utm = {}
|
||||
for punktnummer, koordinate in dict_koordinaten.items():
|
||||
werte = []
|
||||
queue = [koordinate]
|
||||
while queue and len(werte) < 3:
|
||||
v = queue.pop(0)
|
||||
|
||||
# Sympy Matrix
|
||||
if isinstance(v, sp.Matrix):
|
||||
if v.rows * v.cols == 1:
|
||||
queue.insert(0, v[0])
|
||||
else:
|
||||
queue = list(np.array(v.tolist(), dtype=object).reshape(-1)) + queue
|
||||
continue
|
||||
|
||||
# numpy array
|
||||
if isinstance(v, np.ndarray):
|
||||
if v.size == 1:
|
||||
queue.insert(0, v.reshape(-1)[0])
|
||||
else:
|
||||
queue = list(v.reshape(-1)) + queue
|
||||
continue
|
||||
|
||||
# Liste / Tuple
|
||||
if isinstance(v, (list, tuple)):
|
||||
if len(v) == 1:
|
||||
queue.insert(0, v[0])
|
||||
else:
|
||||
queue = list(v) + queue
|
||||
continue
|
||||
|
||||
# Skalar
|
||||
werte.append(float(v))
|
||||
|
||||
if len(werte) < 3:
|
||||
raise ValueError(f"Zu wenig skalare Werte gefunden: {werte}")
|
||||
|
||||
X, Y, Z = werte[0], werte[1], werte[2]
|
||||
|
||||
E, N, H = tr.transform(X, Y, Z)
|
||||
# Runden, weil ansonsten aufgrund begrenzter Rechenkapazität falsche Werte Resultieren
|
||||
dict_koordinaten_utm[punktnummer] = (round(E, 8), round(N, 8), round(H, 8))
|
||||
return dict_koordinaten_utm
|
||||
Reference in New Issue
Block a user