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

Poista yleismääräykset määräysryhmien valikosta, joka luodaan aktiivisesta kaavasta #189

Merged
Show file tree
Hide file tree
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
25 changes: 15 additions & 10 deletions arho_feature_template/core/plan_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import logging
from collections import defaultdict
from typing import TYPE_CHECKING

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


def regulation_group_library_from_active_plan() -> RegulationGroupLibrary:
category_features = list(PlanRegulationGroupTypeLayer.get_features())
category_id_to_name: dict[str, str] = {category["id"]: category["name"][LANGUAGE] for category in category_features}
category_regulation_group_map: dict[str, list[QgsFeature]] = {
feature["name"][LANGUAGE]: [] for feature in category_features
id_of_general_regulation_group_type = PlanRegulationGroupTypeLayer.get_attribute_value_by_another_attribute_value(
"id", "value", "generalRegulations"
)
category_id_to_name: dict[str, str] = {
category["id"]: category["name"][LANGUAGE] for category in PlanRegulationGroupTypeLayer.get_features()
}

regulation_groups_by_category = defaultdict(list)
for feat in RegulationGroupLayer.get_features():
name = category_id_to_name[feat["type_of_plan_regulation_group_id"]]
category_regulation_group_map[name].append(feat)
if feat["type_of_plan_regulation_group_id"] == id_of_general_regulation_group_type:
# Exclude general regulations from the library
continue
category_name = category_id_to_name[feat["type_of_plan_regulation_group_id"]]
regulation_groups_by_category[category_name].append(feat)

return RegulationGroupLibrary(
name="Käytössä olevat kaavamääräysryhmät",
version=None,
Expand All @@ -456,11 +463,9 @@ def regulation_group_library_from_active_plan() -> RegulationGroupLibrary:
RegulationGroupCategory(
category_code=None,
name=category_name,
regulation_groups=[
RegulationGroupLayer.model_from_feature(feat) for feat in category_regulation_groups
],
regulation_groups=[RegulationGroupLayer.model_from_feature(feat) for feat in regulation_groups],
)
for category_name, category_regulation_groups in category_regulation_group_map.items()
for category_name, regulation_groups in regulation_groups_by_category.items()
],
)

Expand Down
6 changes: 4 additions & 2 deletions arho_feature_template/project/layers/code_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def get_id_by_feature_layer_name(cls, layer_name: str) -> str | None:
regulation_group_type = cls.LAYER_NAME_TO_REGULATION_GROUP_TYPE_MAP.get(layer_name)
if not regulation_group_type:
raise LayerNameNotFoundError(layer_name)
attribute_value = cls.get_attribute_value_by_another_attribute_value("id", "value", regulation_group_type)
return cast(str, attribute_value) if attribute_value else attribute_value
regulation_type_id = cls.get_attribute_value_by_another_attribute_value("id", "value", regulation_group_type)
if regulation_type_id:
return cast(str, regulation_type_id)
return None


class PlanRegulationTypeLayer(AbstractCodeLayer):
Expand Down
Loading