diff --git a/mapmaker/flatmap/__init__.py b/mapmaker/flatmap/__init__.py index 7424a482..fadafbd4 100644 --- a/mapmaker/flatmap/__init__.py +++ b/mapmaker/flatmap/__init__.py @@ -288,17 +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 in self.__features_with_id: - pass - else: + 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