Skip to content

Commit

Permalink
add check that polygons dont overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
Santonia27 committed Oct 26, 2023
1 parent 22e9985 commit 018c53a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 86 deletions.
142 changes: 68 additions & 74 deletions examples/aggregation_zones_example.ipynb

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions hydromt_fiat/workflows/aggregation_areas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import geopandas as gpd
from typing import List, Union
from pathlib import Path
import sys

def process_value(value):
if isinstance(value, list) and len(value) == 1:
Expand Down Expand Up @@ -43,6 +44,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 +54,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 018c53a

Please sign in to comment.