Skip to content

Commit

Permalink
Merge pull request #144 from QGEP/2024-05-14-add-missing-filters-inte…
Browse files Browse the repository at this point in the history
…rlis-export

qgepdss/export.py - rohrprofil_geometry etc. add if filtered
  • Loading branch information
ponceta committed Jul 18, 2024
2 parents 9416466 + 5d99389 commit 48c8a7f
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 51 deletions.
7 changes: 6 additions & 1 deletion qgepqwat2ili/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ def action_do_export():
return

# 2. check wastewater_structure for all data models
flag_test = False
# flag_test - set to true if this test should be applied also
flag_test = True
if flag_test:
check_wastewater_structure = False
check_wastewater_structure = check_wastewater_structure_subclass_data()
Expand Down Expand Up @@ -599,6 +600,10 @@ def action_do_export():
#18.3.2023
# 22.3.2023 added try - seems not to work
# try:

# add logger info to check what selection is used
logger.info(f"Start Exporting with selection {str(export_dialog.selected_ids)}")

if emodel == "VSA_KEK_2019_LV95":
logger.info("Start Exporting VSA_KEK_2019_LV95 - qgep_export")
#qgep_export(selection=export_dialog.selected_ids, labels_file=labels_file_path)
Expand Down
33 changes: 29 additions & 4 deletions qgepqwat2ili/qgep/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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 @@ -101,7 +100,7 @@ def modulo_angle(val):
if val is None:
return None

# 5.4.2023 add orientation
# add orientation
val = val + float(labelorientation)

val = val % 360.0
Expand All @@ -113,6 +112,27 @@ 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
"""
# first check for None, as is get_tid
if relation is None:
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 @@ -492,7 +512,9 @@ def textpos_common(row, t_type, geojson_crs_def):
QGEP.reach_point.obj_id == QGEP.reach.fk_reach_point_from,
QGEP.reach_point.obj_id == QGEP.reach.fk_reach_point_to,
),
).filter(QGEP.wastewater_networkelement.obj_id.in_(subset_ids))
).filter(
QGEP.wastewater_networkelement.obj_id.in_(subset_ids)
)
for row in query:

# AVAILABLE FIELDS IN QGEP.reach_point
Expand All @@ -512,7 +534,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
Loading

0 comments on commit 48c8a7f

Please sign in to comment.