You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
write optional function to clip exposure to hazard boundaries
Task list
buildings
roads
def clip_exposure(self, da):
"""
Clip the exposure geometries to the bounding box of the given data array.
This function modifies the exposure geometries by clipping them to the
bounding box of the provided data array. It differentiates between roads
and buildings, updating their respective geometries in the exposure object.
Parameters
----------
da : xarray.DataArray
The data array whose bounding box is used to clip the exposure geometries.
"""
gdf = self.exposure.get_full_gdf(self.exposure.exposure_db)
da_bounding_box =da.rio.bounds()
bbox_coords = [
(da_bounding_box[0], da_bounding_box[1]),
(da_bounding_box[2], da_bounding_box[1]),
(da_bounding_box[2], da_bounding_box[3]),
(da_bounding_box[0], da_bounding_box[3])
]
# Create the gdf from hazard polygons
polygon = Polygon(bbox_coords)
gdf_polygon = gpd.GeoDataFrame(geometry=[polygon])
crs = gdf.crs
gdf_polygon.crs = crs
# Clip the exposure geometries
gdf = gpd.clip(gdf, gdf_polygon)
if gdf["Primary Object Type"].str.contains("road").any():
gdf_roads = gdf[gdf["Primary Object Type"].str.contains("road")]
gdf_buildings= gdf[~gdf.isin(gdf_roads)]
idx_buildings = self.exposure.geom_names.index("buildings")
idx_roads = self.exposure.geom_names.index("roads")
self.exposure.exposure_geoms[idx_buildings] = gdf_buildings[["Object ID", "geometry"]]
self.exposure.exposure_geoms[idx_roads] = gdf_roads[["Object ID", "geometry"]]
else:
self.exposure.exposure_geoms[0] = gdf[["Object ID", "geometry"]]
del gdf["geometry"]
self.exposure.exposure_db = gdf
Use case
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Kind of request
None
Enhancement Description
write optional function to clip exposure to hazard boundaries
Task list
def clip_exposure(self, da):
"""
Clip the exposure geometries to the bounding box of the given data array.
Use case
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: