input(relation: $input_exposures_layer, name: 'exposure') as exposures_input
 -> select({*}) as "geoprocess_exposure"
 -> filter(exposure.Road_type = $input_exposures_filter_expression or $input_exposures_filter_expression = '')
 -> select({*, segment(exposure, $input_exposures_cut_distance) as exposure_cut_geom})
 -> unnest(exposure_cut_geom, 'segmentID')
 -> select({{exposure.*, segmentID, exposure_cut_geom as the_geom} as exposure, measure(exposure_cut_geom) / measure(exposure.the_geom) as scale_factor})
 -> select({{exposure.*, measure(exposure) / 1000 as Length_km} as exposure})
 -> select({exposure})
 -> select({exposure}) as exposures
 -> join(on: true) as exposures_join_hazards
 -> select({*, sample_closest(geometry: exposure, coverage: hazard, buffer-distance: $sample_hazards_buffer) as hazard})
 -> join(on: true) as exposures_join_areas
 -> select({*, sample_closest(geometry: exposure, coverage: area, buffer-distance: $sample_areas_buffer) as area})
 -> select({*}) as sampled
 -> select({*, consequence: map(hazard, hv -> is_exposed(exposure, hv))})
 -> select({*}) as raw_results
 -> select({*}) as event_impact_table
input(value: $input_hazards_layer, name: 'hazard') as hazards_input
 -> select({hazard as hazard}) as hazards
 -> exposures_join_hazards.rhs
input(relation: $input_area_layer, name: 'area') as areas_input
 -> group({to_coverage(area) as area}) as areas
 -> exposures_join_areas.rhs
event_impact_table
 -> select({*}) as "report_event-impact"
 -> filter(hazard >= $min_depth)
 -> group(by: $group_results_by, select: {*, sum(exposure.Length_km) as Exposed_road_km, mean(hazard) as Average_depth})
 -> save(name: 'event-impact') as "save_event-impact"
event_impact_table
 -> select({*}) as "report_exposed-roads"
 -> filter(hazard >= $min_depth)
 -> save(name: 'exposed-roads') as "save_exposed-roads"
