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

alter filtering type for oid prefix selection #222

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(

self.labels_file = labels_file
self.use_vsacode = use_vsacode
self.oid_prefix = None

self.basket_enabled = basket_enabled

Expand Down Expand Up @@ -2402,7 +2403,7 @@ def _modulo_angle(self, val):
return val

def get_oid_prefix(self, oid_table):
instance = self.tww_session.query(oid_table).filter(oid_table.active is True).first()
instance = self.tww_session.query(oid_table).filter(oid_table.active.is_(True)).first()
if instance is None:
logger.warning(
f'Could not find an active entry in table"{oid_table.__table__.schema}.{oid_table.__name__}". \
Expand Down Expand Up @@ -2599,12 +2600,11 @@ def overflow_common(self, row, type_name):
"steuerungszentraleref": self.get_tid(row.fk_control_center__REL),
}

def _textpos_common(self, row, t_type, geojson_crs_def, shortcut_en):
def _textpos_common(self, row, t_type, geojson_crs_def, shortcut_en, oid_prefix):
"""
Returns common attributes for textpos
"""
t_id = self.tid_maker.next_tid()
oid_prefix = self.get_oid_prefix(self.model_classes_tww_sys.oid_prefixes)
if t_id > 999999:
logger.warning(
f"Exporting more than 999999 labels will generate invalid OIDs. Currently exporting {t_id} label of type '{t_type}'."
Expand Down Expand Up @@ -2636,6 +2636,8 @@ def _textpos_common(self, row, t_type, geojson_crs_def, shortcut_en):
def _export_label_positions(self):
logger.info(f"Exporting label positions from {self.labels_file}")

# get oid prefix
self.oid_prefix = self.get_oid_prefix(self.model_classes_tww_sys.oid_prefixes)
# Get t_id by obj_name to create the reference on the labels below
tid_for_obj_id = {
"vw_tww_reach": {},
Expand Down Expand Up @@ -2681,19 +2683,25 @@ def _export_label_positions(self):

if layer_name == "vw_tww_reach":
ili_label = self.model_classes_interlis.haltung_text(
**self._textpos_common(label, "haltung_text", geojson_crs_def, "RX"),
**self._textpos_common(
label, "haltung_text", geojson_crs_def, "RX", self.oid_prefix
),
haltungref=t_id,
)

elif layer_name == "vw_tww_wastewater_structure":
ili_label = self.model_classes_interlis.abwasserbauwerk_text(
**self._textpos_common(label, "abwasserbauwerk_text", geojson_crs_def, "WX"),
**self._textpos_common(
label, "abwasserbauwerk_text", geojson_crs_def, "WX", self.oid_prefix
),
abwasserbauwerkref=t_id,
)

elif layer_name == "catchment_area":
ili_label = self.model_classes_interlis.einzugsgebiet_text(
**self._textpos_common(label, "einzugsgebiet_text", geojson_crs_def, "CX"),
**self._textpos_common(
label, "einzugsgebiet_text", geojson_crs_def, "CX", self.oid_prefix
),
einzugsgebietref=t_id,
)

Expand Down