Skip to content

Commit

Permalink
assure that code doesnt crash if spatial joins are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Santonia27 committed Oct 16, 2024
1 parent bd311de commit 3d02c58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 3 additions & 4 deletions hydromt_fiat/api/hydromt_fiat_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,9 @@ def new_additional_attributes(self, config_yaml):
"setup_additional_attributes"
].new_composite_area
# Check if additional attributes already exist
add_attrs_existing = [
attr["name"]
for attr in self.fiat_model.spatial_joins["additional_attributes"]
]
add_attrs_existing = [ attr["name"]
for attr in self.fiat_model.spatial_joins["additional_attributes"]
] if self.fiat_model.spatial_joins["additional_attributes"] is not None else []
indices_to_remove = []
for i, label_name in enumerate(label_names):
if (
Expand Down
5 changes: 3 additions & 2 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,11 @@ def setup_additional_attributes(
if not self.spatial_joins["additional_attributes"]:
self.spatial_joins["additional_attributes"] = []

# Check if additional attributes already exist
add_attrs_existing = [
attr["name"]
for attr in self.spatial_joins["additional_attributes"]
]
] if self.spatial_joins["additional_attributes"] is not None else []

for label_name, file_name, attribute_name in zip(
label_names, file_names, attribute_names
Expand All @@ -1053,7 +1054,7 @@ def setup_additional_attributes(
"file": f"exposure/additional_attributes/{file_name}.gpkg", # TODO Should we define this location somewhere globally?
"field_name": attribute_name,
}

# If not exist, add to spatial joins
if label_name not in add_attrs_existing:
self.spatial_joins["additional_attributes"].append(attrs)

Expand Down

0 comments on commit 3d02c58

Please sign in to comment.