From 5a20e8d5aa53d6d031ecb850ca3bccd0ce508434 Mon Sep 17 00:00:00 2001 From: napakalas Date: Tue, 26 Aug 2025 21:42:10 +1200 Subject: [PATCH 1/3] Replace feature in __features_with_id when a new feature is created due to .group element containment (#160). --- mapmaker/flatmap/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mapmaker/flatmap/__init__.py b/mapmaker/flatmap/__init__.py index 7424a482..7fa73bcc 100644 --- a/mapmaker/flatmap/__init__.py +++ b/mapmaker/flatmap/__init__.py @@ -296,9 +296,10 @@ def new_feature(self, layer_id: str, geometry, properties, is_group=False) -> Fe feature = Feature(self.__last_geojson_id, geometry, properties, is_group=is_group) self.__features_by_geojson_id[feature.geojson_id] = feature if feature.id: - if feature.id in self.__features_with_id: - pass - else: + if ( + feature.id not in self.__features_with_id + or (feature.get_property('group') and feature.get_property('interior')) + ): self.__features_with_id[feature.id] = feature if self.map_kind == MAP_KIND.FUNCTIONAL: if (name := properties.get('name', '')) != '': From 4dad361b9cce9aab7056294fbed59fa3355f2f63 Mon Sep 17 00:00:00 2001 From: napakalas Date: Thu, 28 Aug 2025 11:43:31 +1200 Subject: [PATCH 2/3] Add option to update FlatMap.__features_with_id when calling new_feature() (#160) --- mapmaker/flatmap/__init__.py | 9 +++------ mapmaker/flatmap/layers.py | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/mapmaker/flatmap/__init__.py b/mapmaker/flatmap/__init__.py index 7fa73bcc..f0915695 100644 --- a/mapmaker/flatmap/__init__.py +++ b/mapmaker/flatmap/__init__.py @@ -288,18 +288,15 @@ def get_feature_by_geojson_id(self, geojson_id: int) -> Optional[Feature]: #========================================================================= return self.__features_by_geojson_id.get(geojson_id) - def new_feature(self, layer_id: str, geometry, properties, is_group=False) -> Feature: - #===================================================================================== + def new_feature(self, layer_id: str, geometry, properties, is_group=False, update_feature_with_id=False) -> Feature: + #====================================================================================================================== self.__last_geojson_id += 1 properties['layer'] = layer_id self.properties_store.update_properties(properties) # Update from JSON properties file feature = Feature(self.__last_geojson_id, geometry, properties, is_group=is_group) self.__features_by_geojson_id[feature.geojson_id] = feature if feature.id: - if ( - feature.id not in self.__features_with_id - or (feature.get_property('group') and feature.get_property('interior')) - ): + if update_feature_with_id or feature.id not in self.__features_with_id: self.__features_with_id[feature.id] = feature if self.map_kind == MAP_KIND.FUNCTIONAL: if (name := properties.get('name', '')) != '': diff --git a/mapmaker/flatmap/layers.py b/mapmaker/flatmap/layers.py index 93960bf3..a4f5fff0 100644 --- a/mapmaker/flatmap/layers.py +++ b/mapmaker/flatmap/layers.py @@ -402,7 +402,7 @@ def add_group_features(self, group_name: str, features: list[Feature], region_properties = base_properties.copy() for region in filter(lambda p: prepared_polygon.contains(p.geometry), regions): region_properties.update(region.properties) - layer_features.append(self.flatmap.new_feature(self.id, polygon, region_properties)) + layer_features.append(self.flatmap.new_feature(self.id, polygon, region_properties, update_feature_with_id=True)) break else: for feature in features: @@ -442,7 +442,7 @@ def add_group_features(self, group_name: str, features: list[Feature], feature_group = self.flatmap.new_feature( self.id, shapely.MultiPolygon(grouped_polygons).buffer(0), - grouped_properties, is_group=True) + grouped_properties, is_group=True, update_feature_with_id=True) layer_features.append(feature_group) # So that any grouped lines don't have a duplicate id grouped_properties.pop('id', None) @@ -459,7 +459,7 @@ def add_group_features(self, group_name: str, features: list[Feature], feature_group = self.flatmap.new_feature( self.id, shapely.MultiLineString(grouped_lines), - grouped_properties, is_group=True) + grouped_properties, is_group=True, update_feature_with_id=True) layer_features.append(feature_group) # Feature specific properties have precedence over group's From cc0bf544ba043782872099aaa52804cc589e34d3 Mon Sep 17 00:00:00 2001 From: napakalas Date: Thu, 28 Aug 2025 11:53:43 +1200 Subject: [PATCH 3/3] simple tidy up (#160) --- mapmaker/flatmap/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapmaker/flatmap/__init__.py b/mapmaker/flatmap/__init__.py index f0915695..fadafbd4 100644 --- a/mapmaker/flatmap/__init__.py +++ b/mapmaker/flatmap/__init__.py @@ -289,7 +289,7 @@ def get_feature_by_geojson_id(self, geojson_id: int) -> Optional[Feature]: return self.__features_by_geojson_id.get(geojson_id) def new_feature(self, layer_id: str, geometry, properties, is_group=False, update_feature_with_id=False) -> Feature: - #====================================================================================================================== + #=================================================================================================================== self.__last_geojson_id += 1 properties['layer'] = layer_id self.properties_store.update_properties(properties) # Update from JSON properties file