Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#189 aggregation polygon overlap #191

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ cache
/examples/FIAT_database
hydromt_fiat/data/damage_functions/flooding/AllDDF_HAZUS_fractions.xlsx
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."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I didn't know about the is_unique function


# 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
Loading