Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-10-30-fix-loosing-coordinates-interlis-import #484

Merged
merged 13 commits into from
Nov 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,44 @@ def get_pk(self, relation):
return None
return relation.t_ili_tid

# new 30.10.2024
def geometry3D_convert(
self, geometryattribute, levelattribute, obj_id, classname_attributename
):
"""
Checks if levelattribute or geometryattribut is Null or empty and calls ST_Force3D accordingly as else 3D geometry will be set to NULL if levelattribute is missing - see https://github.com/teksi/wastewater/issues/475#issuecomment-2441032526 and https://trac.osgeo.org/postgis/ticket/5804#comment:1
"""
if levelattribute is None or levelattribute == "":
if geometryattribute is None or geometryattribute == "":
# No geometry AND no levelattribute provided
logger.warning(
f"No {classname_attributename} and geometry (Lage) provided for object {obj_id} - situation3d_geometry cannot be defined! Object cannot be displayed in TEKSI TWW!"
)
return None

else:
# geometry attribute but no levelattribute provided
geom = self.session_tww.scalar(ST_Force3D(geometryattribute))
logger.info(
f"No {classname_attributename} provided for object {obj_id}- situation3d_geometry with no z-value created: {geom}."
)
return geom
else:
if geometryattribute is None or geometryattribute == "":
# Levelattribute provided but no geometry attribute
logger.warning(
f"{classname_attributename} provided but no geometry (Lage) provided for object {obj_id} - situation3d_geometry cannot be defined! Object cannot be displayed in TEKSI TWW!"
)
return None
else:
# situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.kote)),
# Levelattribute and geometry attribute provided - 3D coordinate can be created as expected
geom = self.session_tww.scalar(ST_Force3D(geometryattribute, levelattribute))
logger.debug(
f" debug: situation3d_geometry created with geometry (x,y) and level (z): {geom}."
)
return geom

def create_or_update(self, cls, **kwargs):
"""
Updates an existing instance (if obj_id is found) or creates an instance of the provided class
Expand Down Expand Up @@ -1937,7 +1975,11 @@ def _import_haltungspunkt(self):
),
position_of_connection=row.lage_anschluss,
remark=row.bemerkung,
situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.kote)),
# 30.10.2024 patching
# situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.kote)),
situation3d_geometry=self.geometry3D_convert(
row.lage, row.kote, row.t_ili_tid, "reach_point.cote (Haltungpunkt.Kote)"
),
)
self.session_tww.add(reach_point)
print(".", end="")
Expand Down Expand Up @@ -1969,7 +2011,15 @@ def _import_abwasserknoten(self):
# fk_hydr_geometry=row.REPLACE_ME, # TODO : NOT MAPPED
backflow_level_current=row.rueckstaukote_ist,
bottom_level=row.sohlenkote,
situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.sohlenkote)),
# situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.sohlenkote)),
# 30.10.2024 patching
# situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.sohlenkote)),
situation3d_geometry=self.geometry3D_convert(
row.lage,
row.sohlenkote,
row.t_ili_tid,
"wastewater_node.bottom_level (Abwasserknoten.Sohlenkote)",
),
)
self.session_tww.add(wastewater_node)
print(".", end="")
Expand Down Expand Up @@ -2079,7 +2129,13 @@ def _import_deckel(self):
positional_accuracy=self.get_vl_code(
self.model_classes_tww_od.cover_positional_accuracy, row.lagegenauigkeit
),
situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.kote)),
# patching 31.10.2024
# situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.kote)),
# 30.10.2024 patching
# situation3d_geometry=self.session_tww.scalar(ST_Force3D(row.lage, row.kote)),
situation3d_geometry=self.geometry3D_convert(
row.lage, row.kote, row.t_ili_tid, "cover.level (Deckel.Deckelkote)"
),
sludge_bucket=self.get_vl_code(
self.model_classes_tww_od.cover_sludge_bucket, row.schlammeimer
),
Expand Down