Skip to content

Commit

Permalink
Added code to ensure waterways are clipped prior to raster value sele…
Browse files Browse the repository at this point in the history
…ction to avoid out of bounds errors
  • Loading branch information
rosepearson committed Sep 8, 2024
1 parent 1820ba8 commit abaa24c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/geofabrics/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3132,7 +3132,9 @@ def estimate_closed_elevations(
self.logger.info("Closed waterways already recorded. ")
return
# If not - estimate elevations along close waterways
closed_waterways = waterways[waterways["tunnel"]]
dem_bounds = geopandas.GeoSeries([shapely.geometry.box(*dem.rio.bounds())], crs=dem.rio.crs)
closed_waterways = waterways.clip(dem_bounds, keep_geom_type=True, sort=True)
closed_waterways = closed_waterways[closed_waterways["tunnel"]]
closed_waterways["polygon"] = closed_waterways.buffer(
closed_waterways["width"].to_numpy()
)
Expand Down Expand Up @@ -3214,7 +3216,9 @@ def estimate_open_elevations(
self.logger.info("Open waterways already recorded. ")
return
# If not - estimate the elevations along the open waterways - drop any invalid geometries
open_waterways = waterways[numpy.logical_not(waterways["tunnel"])]
dem_bounds = geopandas.GeoSeries([shapely.geometry.box(*dem.rio.bounds())], crs=dem.rio.crs)
open_waterways = waterways.clip(dem_bounds, keep_geom_type=True, sort=True)
open_waterways = open_waterways[numpy.logical_not(open_waterways["tunnel"])]
open_waterways = open_waterways[~open_waterways.geometry.isna()]
# sample the ends of the waterway - sample over a polygon at each end
polygons = open_waterways.interpolate(0).buffer(
Expand Down

0 comments on commit abaa24c

Please sign in to comment.