input(relation: 'input.shp', name: 'exposure') as exposures_input
 -> select({*, segment_by_grid(exposure.the_geom, 0.1, align-to: bookmark('hazard.tif')) as segmented}) as segmented
# check we can write the segmented geometry to file. This will fail if it has different geometry types
 -> unnest(segmented, 'segmentID')
 -> select({ segmented as the_geom, segmentID })
 -> save(name: 'segmented_geom', format: 'shapefile')

# sanity-check we end up with the same overall area, more or less
segmented
 -> select({*, map(segmented, geom -> measure(geom) / measure(exposure)) as exposed_ratio})
 -> select({round(sum(exposed_ratio), 3) as exposed_ratio})
 -> save(name: 'exposed', format: 'csv')
