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

if-statemnent unit conversion. read_geoms generalize for file type #419

Merged
merged 5 commits into from
Nov 27, 2024
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
32 changes: 23 additions & 9 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,21 +1284,35 @@ def read_geoms(self):
]
self.exposure.read_geoms(exposure_fn)


fns = glob.glob(Path(self.root, "geoms", "*.geojson").as_posix())
if self.spatial_joins["aggregation_areas"]:
fns_aggregation = glob.glob(Path(self.root, "geoms", "aggregation_areas","*.geojson").as_posix())
fns.append(fns_aggregation[0])
fns_aggregation = []
for i in self.spatial_joins['aggregation_areas']:
fn_aggregation = i['file']
fn_aggregation = str(Path(self.root, fn_aggregation))
fns_aggregation.append(fn_aggregation)
fns.extend(fns_aggregation)
if self.spatial_joins["additional_attributes"]:
if len(glob.glob(Path(self.root, "geoms", "additional_attributes","*.geojson").as_posix())) > 0:
fns_additional_attributes = glob.glob(Path(self.root, "geoms", "additional_attributes","*.geojson").as_posix())
fns.append(fns_additional_attributes[0])
if len(glob.glob(Path(self.root, "geoms", "building_footprints","*.geojson").as_posix())) > 0:
fns_building_footprints = glob.glob(Path(self.root, "geoms", "building_footprints","*.geojson").as_posix())
fns.append(fns_building_footprints[0])
fns_additional_attributes = []
for i in self.spatial_joins['additional_attributes']:
fn_additional_attributes = i['file']
fn_additional_attributes = str(Path(self.root, fn_additional_attributes))
if 'building_footprints' in fn_additional_attributes:
self.building_footprint = gpd.read_file(fn_additional_attributes)
else:
fns_additional_attributes.append(fn_additional_attributes)
fns.extend(fns_additional_attributes)

if len(fns) >= 1:
self.logger.info("Reading static geometries")
for fn in fns:
name = Path(fn).stem
if "aggregation_areas" in fn:
name = f"aggregation_areas/{Path(fn).stem}"
elif "additional_attributes" in fn:
name = f"additional_attributes/{Path(fn).stem}"
else:
name = Path(fn).stem
self.set_geoms(gpd.read_file(fn), name=name)

def write(self):
Expand Down
6 changes: 4 additions & 2 deletions hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,8 @@ def setup_ground_floor_height(
)

# Unit conversion
self.unit_conversion("Ground Floor Height", gfh_unit)
if gfh_unit:
self.unit_conversion("Ground Floor Height", gfh_unit)

if "geometry" in self.exposure_db.columns:
self.exposure_db.drop(columns=["geometry"], inplace=True)
Expand Down Expand Up @@ -1029,7 +1030,8 @@ def setup_ground_elevation(
)

# Unit conversion
self.unit_conversion("Ground Elevation", grnd_elev_unit)
if grnd_elev_unit:
self.unit_conversion(parameter = "Ground Elevation", unit = grnd_elev_unit)

else:
self.logger.warning(
Expand Down
Loading