Skip to content

Commit

Permalink
Merge pull request #191 from Deltares/#189_aggregation_polygon_overlap
Browse files Browse the repository at this point in the history
#189 aggregation polygon overlap
  • Loading branch information
frederique-hub authored Oct 31, 2023
2 parents 027cd1f + a381cb5 commit 4c07018
Show file tree
Hide file tree
Showing 6 changed files with 1,520 additions and 325 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ hydromt_fiat/data/damage_functions/flooding/AllDDF_HAZUS_fractions.xlsx
examples/data/update_ground_floor_height/test_update_ground_floor_height_points
examples/data/update_ground_floor_height/test_update_ground_floor_height_polygons
examples/data/building_footprints/fiat_model_bfs
examples/data/aggregation_zones/output
examples/data/aggregation_zones/output

# notebooks
/examples/aggregation_zones_example_files
/examples/data/aggregation_zones/aggregation_zones_test1/
/examples/data/aggregation_zones/aggregation_zones_test2/
examples/aggregation_zones_example.html
1,776 changes: 1,489 additions & 287 deletions examples/aggregation_zones_example.ipynb

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions examples/data/aggregation_zones/config_aggregation.yml

This file was deleted.

8 changes: 8 additions & 0 deletions examples/data/aggregation_zones/configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
setup_aggregation_areas:
aggregation_area_fn: "data/aggregation_zones/aggregation_zones/base_zones.gpkg"
attribute_names: ZONE_BASE
label_names: Base_zones




13 changes: 13 additions & 0 deletions examples/data/aggregation_zones/configuration_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
setup_aggregation_areas:
aggregation_area_fn:
- "data/aggregation_zones/aggregation_zones/base_zones.gpkg"
- "data/aggregation_zones/aggregation_zones/land_use.gpkg"
- "data/aggregation_zones/aggregation_zones/accomodation_type.gpkg"
attribute_names:
- ZONE_BASE
- LAND_USE
- ACCOM
label_names:
- Base_zones
- Land_use
- Accommodation_type
15 changes: 3 additions & 12 deletions hydromt_fiat/workflows/aggregation_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def join_exposure_aggregation_multiple_areas(


assert attribute_name in aggregation_gdf.columns, f"Attribute {attribute_name} not found in {file_path}"


# If you overwrite the exposure_gdf with the joined data, you can append all
# aggregation areas to the same exposure_gdf
Expand All @@ -52,19 +53,9 @@ def join_exposure_aggregation_multiple_areas(
op="intersects",
how="left",
)

assert exposure_gdf["Object ID"].is_unique, "Error! Polygons overlap! Please clean your data from overlaping features."

# aggregate the data if duplicates exist
aggregated = (
exposure_gdf.groupby("Object ID")[attribute_name].agg(list).reset_index()
)
exposure_gdf.drop_duplicates(subset="Object ID", keep="first", inplace=True)
exposure_gdf.drop(columns=attribute_name, inplace=True)
exposure_gdf = exposure_gdf.merge(aggregated, on="Object ID")

# Create a string from the list of values in the duplicated aggregation area
# column
exposure_gdf[attribute_name] = exposure_gdf[attribute_name].apply(process_value)

# Rename the 'aggregation_attribute' column to 'new_column_name'. Put in
# Documentation that the order the user put the label name must be the order of the gdf
exposure_gdf.rename(columns={attribute_name: f"Aggregation Label: {label_name}"}, inplace=True)
Expand Down

0 comments on commit 4c07018

Please sign in to comment.