Skip to content

Commit 5c6c0c1

Browse files
nmaarnioLKajan
authored andcommitted
remove general regulations from regulation group library generated from active plan
This way there shouldn't be any chance a plan regulation group widget to be created from a general regulation, preventing the case where the plan is counted as a plan feature linked to a regulation group. This change is also a fix in itself because it shouldn't be possible to assign general regulations for plan features.
1 parent 32876bd commit 5c6c0c1

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

arho_feature_template/core/plan_manager.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import logging
5+
from collections import defaultdict
56
from typing import TYPE_CHECKING
67

78
from qgis.core import QgsProject, QgsVectorLayer, QgsWkbTypes
@@ -439,15 +440,21 @@ def unload(self):
439440

440441

441442
def regulation_group_library_from_active_plan() -> RegulationGroupLibrary:
442-
category_features = list(PlanRegulationGroupTypeLayer.get_features())
443-
category_id_to_name: dict[str, str] = {category["id"]: category["name"][LANGUAGE] for category in category_features}
444-
category_regulation_group_map: dict[str, list[QgsFeature]] = {
445-
feature["name"][LANGUAGE]: [] for feature in category_features
443+
id_of_general_regulation_group_type = PlanRegulationGroupTypeLayer.get_attribute_value_by_another_attribute_value(
444+
"id", "value", "generalRegulations"
445+
)
446+
category_id_to_name: dict[str, str] = {
447+
category["id"]: category["name"][LANGUAGE] for category in PlanRegulationGroupTypeLayer.get_features()
446448
}
447449

450+
regulation_groups_by_category = defaultdict(list)
448451
for feat in RegulationGroupLayer.get_features():
449-
name = category_id_to_name[feat["type_of_plan_regulation_group_id"]]
450-
category_regulation_group_map[name].append(feat)
452+
if feat["type_of_plan_regulation_group_id"] == id_of_general_regulation_group_type:
453+
# Exclude general regulations from the library
454+
continue
455+
category_name = category_id_to_name[feat["type_of_plan_regulation_group_id"]]
456+
regulation_groups_by_category[category_name].append(feat)
457+
451458
return RegulationGroupLibrary(
452459
name="Käytössä olevat kaavamääräysryhmät",
453460
version=None,
@@ -456,11 +463,9 @@ def regulation_group_library_from_active_plan() -> RegulationGroupLibrary:
456463
RegulationGroupCategory(
457464
category_code=None,
458465
name=category_name,
459-
regulation_groups=[
460-
RegulationGroupLayer.model_from_feature(feat) for feat in category_regulation_groups
461-
],
466+
regulation_groups=[RegulationGroupLayer.model_from_feature(feat) for feat in regulation_groups],
462467
)
463-
for category_name, category_regulation_groups in category_regulation_group_map.items()
468+
for category_name, regulation_groups in regulation_groups_by_category.items()
464469
],
465470
)
466471

0 commit comments

Comments
 (0)