diff --git a/qgepqwat2ili/qgep/export.py b/qgepqwat2ili/qgep/export.py index f45a17ac..aa681acd 100644 --- a/qgepqwat2ili/qgep/export.py +++ b/qgepqwat2ili/qgep/export.py @@ -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. @@ -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 @@ -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), diff --git a/qgepqwat2ili/qgepdss/export.py b/qgepqwat2ili/qgepdss/export.py index 313beb07..a77a030a 100644 --- a/qgepqwat2ili/qgepdss/export.py +++ b/qgepqwat2ili/qgepdss/export.py @@ -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), diff --git a/qgepqwat2ili/qgepsia405/export.py b/qgepqwat2ili/qgepsia405/export.py index a8a8cf48..d7ffae0e 100644 --- a/qgepqwat2ili/qgepsia405/export.py +++ b/qgepqwat2ili/qgepsia405/export.py @@ -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 @@ -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),