Skip to content

Commit

Permalink
Merge pull request #169 from QGEP/2024-10-17-fix-Crash-if-there-are-n…
Browse files Browse the repository at this point in the history
…o-labels-on-export

[WIP] Add except if geojson_crs_def cannot be defined
  • Loading branch information
ponceta authored Oct 18, 2024
2 parents 6ff9fa4 + 8a57ad3 commit aec770d
Showing 1 changed file with 51 additions and 43 deletions.
94 changes: 51 additions & 43 deletions qgepqwat2ili/qgepdss/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3795,63 +3795,71 @@ def textpos_common(row, t_type, geojson_crs_def):
with open(labels_file) as labels_file_handle:
labels = json.load(labels_file_handle)

geojson_crs_def = labels["crs"]

for label in labels["features"]:
layer_name = label["properties"]["Layer"]
obj_id = label["properties"]["qgep_obj_id"]

print(f"label[properties]: {label['properties']}")
try:
geojson_crs_def = labels["crs"]
except Exception:
logger.warning("No labels available - no labels will be exported")
else:
for label in labels["features"]:
layer_name = label["properties"]["Layer"]
obj_id = label["properties"]["qgep_obj_id"]

if not label["properties"]["LabelText"]:
logger.warning(
f"Label of object '{obj_id}' from layer '{layer_name}' is empty and will not be exported"
)
continue
print(f"label[properties]: {label['properties']}")

if layer_name == "vw_qgep_reach":
if obj_id not in tid_for_obj_id["haltung"]:
if not label["properties"]["LabelText"]:
logger.warning(
f"Label for haltung `{obj_id}` exists, but that object is not part of the export"
f"Label of object '{obj_id}' from layer '{layer_name}' is empty and will not be exported"
)
continue
ili_label = ABWASSER.haltung_text(
**textpos_common(label, "haltung_text", geojson_crs_def),
haltungref=tid_for_obj_id["haltung"][obj_id],
)

elif layer_name == "vw_qgep_wastewater_structure":
if obj_id not in tid_for_obj_id["abwasserbauwerk"]:
logger.warning(
f"Label for abwasserbauwerk `{obj_id}` exists, but that object is not part of the export"
if layer_name == "vw_qgep_reach":
if obj_id not in tid_for_obj_id["haltung"]:
logger.warning(
f"Label for haltung (reach) `{obj_id}` exists, but that object is not part of the export"
)
continue
ili_label = ABWASSER.haltung_text(
**textpos_common(label, "haltung_text (reach_text)", geojson_crs_def),
haltungref=tid_for_obj_id["haltung"][obj_id],
)
continue
ili_label = ABWASSER.abwasserbauwerk_text(
**textpos_common(label, "abwasserbauwerk_text", geojson_crs_def),
abwasserbauwerkref=tid_for_obj_id["abwasserbauwerk"][obj_id],
)

elif layer_name == "catchment_area":
if obj_id not in tid_for_obj_id["einzugsgebiet"]:
elif layer_name == "vw_qgep_wastewater_structure":
if obj_id not in tid_for_obj_id["abwasserbauwerk"]:
logger.warning(
f"Label for abwasserbauwerk (wastewater_structure) `{obj_id}` exists, but that object is not part of the export"
)
continue
ili_label = ABWASSER.abwasserbauwerk_text(
**textpos_common(label, "abwasserbauwerk_text", geojson_crs_def),
abwasserbauwerkref=tid_for_obj_id["abwasserbauwerk"][obj_id],
)

elif layer_name == "catchment_area":
if obj_id not in tid_for_obj_id["einzugsgebiet"]:
logger.warning(
f"Label for einzugsgebiet (catchment_area) `{obj_id}` exists, but that object is not part of the export"
)
continue
ili_label = ABWASSER.einzugsgebiet_text(
**textpos_common(
label, "einzugsgebiet_text (catchment_area_text)", geojson_crs_def
),
einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id],
)

else:
logger.warning(
f"Label for einzugsgebiet `{obj_id}` exists, but that object is not part of the export"
f"Unknown layer for label `{layer_name}`. Label will be ignored",
)
continue
ili_label = ABWASSER.einzugsgebiet_text(
**textpos_common(label, "einzugsgebiet_text", geojson_crs_def),
einzugsgebietref=tid_for_obj_id["einzugsgebiet"][obj_id],
)

else:
logger.warning(
f"Unknown layer for label `{layer_name}`. Label will be ignored",
)
continue
abwasser_session.add(ili_label)

abwasser_session.add(ili_label)
print(".", end="")
logger.info("done")
abwasser_session.flush()

finally:
logger.info("done")
abwasser_session.flush()

# -- extra commit
abwasser_session.commit()
Expand Down

0 comments on commit aec770d

Please sign in to comment.