From abaa24cad42e58d41487c9555cd8b8e9bf0b2828 Mon Sep 17 00:00:00 2001 From: rosepearson Date: Mon, 9 Sep 2024 09:26:10 +1200 Subject: [PATCH] Added code to ensure waterways are clipped prior to raster value selection to avoid out of bounds errors --- src/geofabrics/processor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/geofabrics/processor.py b/src/geofabrics/processor.py index 747129e5..18e5c4e6 100644 --- a/src/geofabrics/processor.py +++ b/src/geofabrics/processor.py @@ -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() ) @@ -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(