Skip to content

Commit

Permalink
fix multipolygon error
Browse files Browse the repository at this point in the history
  • Loading branch information
Santonia27 committed Nov 7, 2024
1 parent fde741e commit c0ea7d5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions hydromt_fiat/workflows/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ def join_spatial_data(
f"{get_crs_str_from_gdf(left_gdf.crs)}."
)
right_gdf = right_gdf.to_crs(left_gdf.crs)

if 'MultiPolygon' in list(left_gdf.geom_type.unique()):
for index, row in left_gdf.iterrows():
if row['geometry'].geom_type == "MultiPolygon":
largest_polygon = max(row['geometry'].geoms, key=lambda a: a.area)
left_gdf.at[index, 'geometry'] = largest_polygon
assert len(left_gdf.geom_type.unique()) == 1

if 'MultiPolygon' in list(right_gdf.geom_type.unique()):
for index, row in right_gdf.iterrows():
if row['geometry'].geom_type == "MultiPolygon":
largest_polygon = max(row['geometry'].geoms, key=lambda a: a.area)
right_gdf.at[index, 'geometry'] = largest_polygon
assert len(right_gdf.geom_type.unique()) == 1

left_gdf_type = check_geometry_type(left_gdf)
right_gdf_type = check_geometry_type(right_gdf)
Expand Down

0 comments on commit c0ea7d5

Please sign in to comment.