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

include oid_prefix in interlis text class export #207

Merged
merged 9 commits into from
Apr 18, 2024
1 change: 1 addition & 0 deletions plugin/teksi_wastewater/interlis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TWW_DEFAULT_PGSERVICE = "pg_tww"
TWW_OD_SCHEMA = "tww_od"
TWW_VL_SCHEMA = "tww_vl"
TWW_SYS_SCHEMA = "tww_sys"
ABWASSER_SCHEMA = "pg2ili_abwasser"
MODEL_NAME_VSA_KEK = "VSA_KEK_2020_1_LV95"
MODEL_NAME_SIA405_ABWASSER = "SIA405_ABWASSER_2020_1_LV95"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
ModelInterlisSia405Abwasser,
)
from .interlis_model_mapping.model_interlis_vsa_kek import ModelInterlisVsaKek
from .interlis_model_mapping.model_tww import ModelTwwSys, ModelTwwVl
from .interlis_model_mapping.model_tww_od import ModelTwwOd
from .interlis_model_mapping.model_tww_vl import ModelTwwVl
from .utils.ili2db import InterlisTools
from .utils.various import (
CmdException,
Expand Down Expand Up @@ -62,6 +62,7 @@ def __init__(self, progress_done_callback=None):
self.model_classes_interlis = None
self.model_classes_tww_od = None
self.model_classes_tww_vl = None
self.model_classes_tww_sys = None

self.current_progress = 0

Expand Down Expand Up @@ -321,6 +322,7 @@ def _export_to_intermediate_schema(
model_classes_interlis=self.model_classes_interlis,
model_classes_tww_od=self.model_classes_tww_od,
model_classes_tww_vl=self.model_classes_tww_vl,
model_classes_tww_sys=self.model_classes_tww_sys,
selection=selected_ids,
labels_file=labels_file_path,
basket_enabled=basket_enabled,
Expand Down Expand Up @@ -459,6 +461,10 @@ def _init_model_classes(self, model):
self.model_classes_tww_vl = ModelTwwVl().classes()
self._progress_done(self.current_progress + 1)

if self.model_classes_tww_sys is None:
self.model_classes_tww_sys = ModelTwwSys().classes()
self._progress_done(self.current_progress + 1)

def _progress_done_intermediate_schema(self):
self._progress_done(self.current_progress + 0.5)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(
model_classes_interlis,
model_classes_tww_od,
model_classes_tww_vl,
model_classes_tww_sys,
selection=None,
labels_file=None,
basket_enabled=False,
Expand Down Expand Up @@ -47,6 +48,7 @@ def __init__(
self.model_classes_interlis = model_classes_interlis
self.model_classes_tww_od = model_classes_tww_od
self.model_classes_tww_vl = model_classes_tww_vl
self.model_classes_tww_sys = model_classes_tww_sys

self.tww_session = None
self.abwasser_session = None
Expand Down Expand Up @@ -2399,6 +2401,16 @@ def _modulo_angle(self, val):
val = 0
return val

def get_oid_prefix(self, oid_table):
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__}". Setting to default instead.'
)
return "ch080txt" # TODO: is this prefix owned by TEKSI?

return instance.prefix

def base_common(self, row, type_name):
"""
Returns common attributes for base
Expand Down Expand Up @@ -2589,7 +2601,7 @@ def _textpos_common(self, row, t_type, geojson_crs_def, shortcut_en):
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 All @@ -2598,7 +2610,7 @@ def _textpos_common(self, row, t_type, geojson_crs_def, shortcut_en):
return {
"t_id": t_id,
"t_type": t_type,
"t_ili_tid": f"ch080txt{shortcut_en}{t_id:06d}",
"t_ili_tid": f"{oid_prefix}{shortcut_en}{t_id:06d}",
# --- TextPos ---
"textpos": ST_GeomFromGeoJSON(
json.dumps(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
class ModelTwwVl(ModelBase):
def __init__(self):
super().__init__(config.TWW_VL_SCHEMA)


class ModelTwwSys(ModelBase):
def __init__(self):
super().__init__(config.TWW_SYS_SCHEMA)