Skip to content

Commit

Permalink
add check_fk_in_subsetid to qgep and qgepsia405
Browse files Browse the repository at this point in the history
  • Loading branch information
sjib committed Jun 14, 2024
1 parent 1c13752 commit 63fec54
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
23 changes: 21 additions & 2 deletions qgepqwat2ili/qgep/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from .model_abwasser import get_abwasser_model
from .model_qgep import get_qgep_model

#def qgep_export(selection=None, labels_file=None):
def qgep_export(selection=None, labels_file=None, orientation=None):
"""
Export data from the QGEP model into the ili2pg model.
Expand Down Expand Up @@ -108,6 +107,23 @@ def modulo_angle(val):

return val

def check_fk_in_subsetid (subset, relation):
"""
checks, whether foreignkey is in the subset_ids - if yes it return the tid of the foreignkey, if no it will return None
"""
logger.info(f"check_fk_in_subsetid - Subset ID's '{subset}'")
# get the value of the fk_ attribute as str out of the relation to be able to check whether it is in the subset
fremdschluesselstr = getattr(relation, "obj_id")
logger.info(f"check_fk_in_subsetid - fremdschluesselstr '{fremdschluesselstr}'")

if fremdschluesselstr in subset:
logger.info(f"check_fk_in_subsetid - '{fremdschluesselstr}' is in subset ")
logger.info(f"check_fk_in_subsetid - tid = '{tid_maker.tid_for_row(relation)}' ")
return tid_maker.tid_for_row(relation)
else:
logger.info(f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!")
return None

def create_metaattributes(row):
metaattribute = ABWASSER.metaattribute(
# FIELDS TO MAP TO ABWASSER.metaattribute
Expand Down Expand Up @@ -507,7 +523,10 @@ def textpos_common(row, t_type, geojson_crs_def):
# --- sia405_baseclass ---
**base_common(row, "haltungspunkt"),
# --- haltungspunkt ---
abwassernetzelementref=get_tid(row.fk_wastewater_networkelement__REL),

# changed call from get_tid to check_fk_in_subsetid so it does not wirte foreignkeys on elements that do not exist
#abwassernetzelementref=get_tid(row.fk_wastewater_networkelement__REL),
abwassernetzelementref=check_fk_in_subsetid(subset_ids, row.fk_wastewater_networkelement__REL),
auslaufform=get_vl(row.outlet_shape__REL),
bemerkung=truncate(emptystr_to_null(row.remark), 80),
bezeichnung=null_to_emptystr(row.identifier),
Expand Down
2 changes: 1 addition & 1 deletion qgepqwat2ili/qgepdss/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1991,8 +1991,8 @@ def textpos_common(row, t_type, geojson_crs_def):
**base_common(row, "haltungspunkt"),
# --- haltungspunkt ---

# changed call from get_tid to check_fk_in_subsetid so it does not wirte foreignkeys on elements that do not exist
#abwassernetzelementref=get_tid(row.fk_wastewater_networkelement__REL),
# abwassernetzelementref=get_tid(check_fk_in_subsetid(subset_ids, row.fk_wastewater_networkelement__REL)),
abwassernetzelementref=check_fk_in_subsetid(subset_ids, row.fk_wastewater_networkelement__REL),
auslaufform=get_vl(row.outlet_shape__REL),
bemerkung=truncate(emptystr_to_null(row.remark), 80),
Expand Down
22 changes: 21 additions & 1 deletion qgepqwat2ili/qgepsia405/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ def modulo_angle(val):

return val

def check_fk_in_subsetid (subset, relation):
"""
checks, whether foreignkey is in the subset_ids - if yes it return the tid of the foreignkey, if no it will return None
"""
logger.info(f"check_fk_in_subsetid - Subset ID's '{subset}'")
# get the value of the fk_ attribute as str out of the relation to be able to check whether it is in the subset
fremdschluesselstr = getattr(relation, "obj_id")
logger.info(f"check_fk_in_subsetid - fremdschluesselstr '{fremdschluesselstr}'")

if fremdschluesselstr in subset:
logger.info(f"check_fk_in_subsetid - '{fremdschluesselstr}' is in subset ")
logger.info(f"check_fk_in_subsetid - tid = '{tid_maker.tid_for_row(relation)}' ")
return tid_maker.tid_for_row(relation)
else:
logger.info(f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!")
return None

def create_metaattributes(row):
metaattribute = ABWASSER.metaattribute(
# FIELDS TO MAP TO ABWASSER.metaattribute
Expand Down Expand Up @@ -506,7 +523,10 @@ def textpos_common(row, t_type, geojson_crs_def):
# --- sia405_baseclass ---
**base_common(row, "haltungspunkt"),
# --- haltungspunkt ---
abwassernetzelementref=get_tid(row.fk_wastewater_networkelement__REL),

# changed call from get_tid to check_fk_in_subsetid so it does not wirte foreignkeys on elements that do not exist
#abwassernetzelementref=get_tid(row.fk_wastewater_networkelement__REL),
abwassernetzelementref=check_fk_in_subsetid(subset_ids, row.fk_wastewater_networkelement__REL),
auslaufform=get_vl(row.outlet_shape__REL),
bemerkung=truncate(emptystr_to_null(row.remark), 80),
bezeichnung=null_to_emptystr(row.identifier),
Expand Down

0 comments on commit 63fec54

Please sign in to comment.