# Use group step to produce a shapefile with aggregated information - help!

**URL:** <https://community.riskscape.org.nz/t/use-group-step-to-produce-a-shapefile-with-aggregated-information-help/150>\
**Category:** Community\
**Created:** [2 October 2023 13:35 UTC](https://community.riskscape.org.nz/t/use-group-step-to-produce-a-shapefile-with-aggregated-information-help/150 "2023-10-02T13:35:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emma.dyer](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@emma.dyer](https://community.riskscape.org.nz/u/emma.dyer)\
**Post date:** [2 October 2023 13:35 UTC](https://community.riskscape.org.nz/t/use-group-step-to-produce-a-shapefile-with-aggregated-information-help/150/1 "2023-10-02T13:35:59Z")

</div>

Hello,

I am using RiskScape to calculate risk from a large event set (NetCDF). I have managed to calculate the required metric for each exposed asset for every event but want to aggregate to get average annual risk. I have been able to use the group step to group by exposure ID and year but get the output as a table with no other information e.g. I lose the event\_id and year info. How can I group the data but produce shp output? i.e. I would like a map with the average annual risk in each grid (my exposure data is gridded NetCDF).

Thanks for any advice!  
Emma

---

<div class="post-metadata">

**Author:** ![timbeale](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@timbeale](https://community.riskscape.org.nz/u/timbeale)\
**Post date:** [2 October 2023 20:16 UTC](https://community.riskscape.org.nz/t/use-group-step-to-produce-a-shapefile-with-aggregated-information-help/150/2 "2023-10-02T20:16:32Z")

</div>

Hi Emma,

It depends a bit on your input data and your type of model (Monte Carlo vs hazard-based probabilistic, etc). But presumably your exposure data will have geometry associated with it, so if you group by the whole exposure (rather than just the exposure ID), then the geometry should be retained in the final results, and you would get a shapefile output rather than CSV.

So for example, if your hazard data is event-based (aka Monte Carlo), then you can follow the pipeline example here:  
[https://riskscape.org.nz/docs/advanced/probabilistic/event-based.html#pipeline](https://riskscape.org.nz/docs/advanced/probabilistic/event-based.html#pipeline)

However, you would need to update the `group` steps so that they grouped by the exposure, e.g.

```auto
event_loss_table
  ->
# sum the losses by year to get a yearly loss for each exposure
group(
    by: { exposure, year },
    select: {
        *,
        sum(total_loss) as per_year_loss
    })
  ->
# turn the yearly losses into a list, so it's easier to work with
group(
    by: exposure,
    select: {
        *,
        to_list(per_year_loss) as yearly_losses
    })
 ->
...

```

You would also have to make sure the subsequent `select` steps also all contain either ‘`*`’ or ‘`exposure`’.

Hope that helps.  
Tim

---

<div class="post-metadata">

**Author:** ![emma.dyer](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@emma.dyer](https://community.riskscape.org.nz/u/emma.dyer)\
**Post date:** [3 October 2023 11:34 UTC](https://community.riskscape.org.nz/t/use-group-step-to-produce-a-shapefile-with-aggregated-information-help/150/3 "2023-10-03T11:34:09Z")

</div>

Great, that worked! Thanks very much for your help.  
Emma
