diff --git a/examples/data/setup_new_composite_area/test_read/exposure/aggregation_areas/block_groups.gpkg b/examples/data/setup_new_composite_area/test_read/exposure/aggregation_areas/block_groups.gpkg new file mode 100644 index 00000000..d502c14f Binary files /dev/null and b/examples/data/setup_new_composite_area/test_read/exposure/aggregation_areas/block_groups.gpkg differ diff --git a/hydromt_fiat/workflows/exposure_vector.py b/hydromt_fiat/workflows/exposure_vector.py index ee6d6178..14487a0d 100644 --- a/hydromt_fiat/workflows/exposure_vector.py +++ b/hydromt_fiat/workflows/exposure_vector.py @@ -36,6 +36,8 @@ get_road_lengths, ) +from hydromt_fiat.workflows.aggregation_areas import join_exposure_aggregation_areas + class ExposureVector(Exposure): _REQUIRED_COLUMNS = ["Object ID", "Extraction Method", "Ground Floor Height"] @@ -913,9 +915,10 @@ def setup_new_composite_areas( elevation_reference: str, path_ref: str = None, attr_ref: str = None, - ground_elevation: Union[ - int, float, None, str, Path, List[str], List[Path] - ] = None, + ground_elevation: Union[None, str, Path] = None, + aggregation_area_fn: Union[List[str], List[Path], str, Path] = None, + attribute_names: Union[List[str], str] = None, + label_names: Union[List[str], str] = None, ) -> None: """Adds one or multiple (polygon) areas to the exposure database with a composite damage function and a percentage of the total damage. @@ -1015,7 +1018,9 @@ def setup_new_composite_areas( # TODO: Take ground elevation from DEM? # For water level calculation this will not take into account the # non-flooded cells separately, just averaged over the whole area. - self.logger.warning("The ground elevation is set to 0.") + self.logger.warning( + "The ground elevation is set to 0 if no DEM is supplied." + ) # Idea: Reduction factor for the part of the area is not build-up? @@ -1079,17 +1084,34 @@ def setup_new_composite_areas( self.crs, ) + # Update the exposure_geoms + self.set_geom_names("new_development_area") + self.set_exposure_geoms(_new_exposure_geoms) + + # If the user supplied ground elevation data, assign that to the new + # composite areas + if ground_elevation is not None: + new_objects["Ground Elevation"] = ground_elevation_from_dem( + ground_elevation=ground_elevation, + exposure_db=new_objects, + exposure_geoms=_new_exposure_geoms, + ) + + # If the user supplied aggregation area data, assign that to the + # new composite areas + if aggregation_area_fn is not None: + new_objects = join_exposure_aggregation_areas( + _new_exposure_geoms.merge(new_objects, on="Object ID"), + aggregation_area_fn=aggregation_area_fn, + attribute_names=attribute_names, + label_names=label_names, + ) + # Update the exposure_db self.exposure_db = pd.concat([self.exposure_db, new_objects]).reset_index( drop=True ) - # Update the exposure_geoms - self.set_exposure_geoms(_new_exposure_geoms) - - # Adding elevation data into the new objects - self.setup_ground_elevation(ground_elevation) - def link_exposure_vulnerability( self, exposure_linking_table: pd.DataFrame, diff --git a/tests/test_setup_new_composite_areas_ground_elevation.py b/tests/test_setup_new_composite_areas_ground_elevation.py index d6c1c67c..c7bea9c5 100644 --- a/tests/test_setup_new_composite_areas_ground_elevation.py +++ b/tests/test_setup_new_composite_areas_ground_elevation.py @@ -23,8 +23,10 @@ "type": "datum", "path_ref": None, "attr_ref": None, - "ground_elevation_file": DATADIRDEM - / "charleston_14m.tif", + "ground_elevation_file": None, + "aggregation_area_fn": None, + "attribute_names": None, + "label_names": None, }, "setup_new_composite_area_geom": { "dir": "test_read", @@ -33,8 +35,10 @@ "type": "geom", "path_ref": DATADIR / "new_composite_areas" / "reference_groundHeight_test.shp", "attr_ref": "bfe", - "ground_elevation_file": DATADIRDEM - / "charleston_14m.tif", + "ground_elevation_file": None, + "aggregation_area_fn": None, + "attribute_names": None, + "label_names": None, }, "setup_new_composite_area_elevation": { "dir": "test_read", @@ -45,6 +49,9 @@ "attr_ref": None, "ground_elevation_file": DATADIRDEM / "charleston_14m.tif", + "aggregation_area_fn": EXAMPLEDIR.joinpath("test_read", "exposure", "aggregation_areas", "block_groups.gpkg"), + "attribute_names": "GEOID_short", + "label_names": "Aggregation Label: Census Block", }, } @@ -70,6 +77,9 @@ def test_setup_new_composite_areas_ground_elevation(case): path_ref=_cases[case]["path_ref"], attr_ref=_cases[case]["attr_ref"], ground_elevation=_cases[case]["ground_elevation_file"], + aggregation_area_fn=_cases[case]["aggregation_area_fn"], + attribute_names=_cases[case]["attribute_names"], + label_names=_cases[case]["label_names"], ) if _cases[case]["new_root"].exists():