Skip to content

Commit d5329d1

Browse files
committed
add plan regulation group associations
1 parent ca578da commit d5329d1

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

arho_feature_template/core/plan_manager.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
PlanFeatureLayer,
2828
PlanLayer,
2929
PlanRegulationLayer,
30+
RegulationGroupAssociationLayer,
3031
RegulationGroupLayer,
3132
plan_layers,
3233
)
@@ -229,7 +230,7 @@ def save_plan(plan_data: Plan) -> QgsFeature:
229230
for regulation_group in plan_data.general_regulations:
230231
plan_id = plan_feature["id"]
231232
regulation_group_feature = save_regulation_group(regulation_group, plan_id)
232-
save_regulation_grop_assosiation(plan_id, regulation_group_feature["id"])
233+
save_regulation_group_association(regulation_group_feature["id"], PlanLayer.name, plan_id)
233234

234235
return plan_feature
235236

@@ -250,11 +251,9 @@ def save_plan_feature(plan_feature: PlanFeature, plan_id: str | None = None) ->
250251
if not layer_class:
251252
msg = f"Could not find plan feature layer class for layer name {plan_feature.layer_name}"
252253
raise ValueError(msg)
253-
feature = layer_class.feature_from_model(plan_feature)
254-
layer = layer_class.get_from_project()
255254

256-
if plan_id:
257-
feature["plan_id"] = plan_id
255+
feature = layer_class.feature_from_model(plan_feature, plan_id)
256+
layer = layer_class.get_from_project()
258257

259258
_save_feature(
260259
feature=feature,
@@ -266,7 +265,8 @@ def save_plan_feature(plan_feature: PlanFeature, plan_id: str | None = None) ->
266265
# Handle regulation groups
267266
if plan_feature.regulation_groups:
268267
for group in plan_feature.regulation_groups:
269-
save_regulation_group(group)
268+
regulation_group_feature = save_regulation_group(group)
269+
save_regulation_group_association(regulation_group_feature["id"], plan_feature.layer_name, feature["id"])
270270

271271
return feature
272272

@@ -291,8 +291,13 @@ def save_regulation_group(regulation_group: RegulationGroup, plan_id: str | None
291291
return feature
292292

293293

294-
def save_regulation_grop_assosiation(plan_id: str, regulation_group_id: str):
295-
pass
294+
def save_regulation_group_association(regulation_group_id: str, layer_name: str, feature_id: str) -> QgsFeature:
295+
feature = RegulationGroupAssociationLayer.feature_from(regulation_group_id, layer_name, feature_id)
296+
layer = RegulationGroupAssociationLayer.get_from_project()
297+
298+
_save_feature(feature=feature, layer=layer, id_=None, edit_text="Kaavamääräysryhmän assosiaation lisäys")
299+
300+
return feature
296301

297302

298303
def save_regulation(regulation: Regulation) -> QgsFeature:

arho_feature_template/project/layers/plan_layers.py

+24
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,30 @@ class RegulationGroupAssociationLayer(AbstractPlanLayer):
155155
)
156156
)
157157

158+
layer_name_to_attribute_map: ClassVar[dict[str, str]] = {
159+
LandUsePointLayer.name: "land_use_point_id",
160+
OtherAreaLayer.name: "other_area_id",
161+
OtherPointLayer.name: "other_point_id",
162+
LandUseAreaLayer.name: "land_use_area_id",
163+
LineLayer.name: "line_id",
164+
PlanLayer.name: "plan_id",
165+
}
166+
167+
@classmethod
168+
def feature_from(cls, regulation_group_id: str, layer_name: str, feature_id: str) -> QgsFeature:
169+
layer = cls.get_from_project()
170+
171+
feature = QgsVectorLayerUtils.createFeature(layer)
172+
feature["plan_regulation_group_id"] = regulation_group_id
173+
174+
attribute = cls.layer_name_to_attribute_map.get(layer_name)
175+
if not attribute:
176+
msg = f"Unrecognized layer name given for saving regulation group association: {layer_name}"
177+
raise ValueError(msg)
178+
feature[attribute] = feature_id
179+
180+
return feature
181+
158182

159183
class PlanRegulationLayer(AbstractPlanLayer):
160184
name = "Kaavamääräys"

0 commit comments

Comments
 (0)