# Pipeline running slow when area layer is being used

**URL:** <https://community.riskscape.org.nz/t/pipeline-running-slow-when-area-layer-is-being-used/191>\
**Category:** Community\
**Created:** [30 September 2024 19:53 UTC](https://community.riskscape.org.nz/t/pipeline-running-slow-when-area-layer-is-being-used/191 "2024-09-30T19:53:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rebeccawelsh](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@rebeccawelsh](https://community.riskscape.org.nz/u/rebeccawelsh)\
**Post date:** [30 September 2024 19:53 UTC](https://community.riskscape.org.nz/t/pipeline-running-slow-when-area-layer-is-being-used/191/1 "2024-09-30T19:53:17Z")

</div>

Kia ora,  
I am trying to run a pipeline with multiple hazard and exposure layers. I am joining these to NZ regional boundaries and once I include this step the pipeline is running so much slower. Is something wrong with my code that would speed up the process more? I’ve added in the snippet on area layers.

Thanks!

input(relation: ‘Population’, name: ‘population’)  
 → select({population}) as populations  
 → join(on: true) as population\_join\_areas3  
 → select({_, sample\_one(geometry:population, coverage: area3) as area3})  
 → join(on: true) as population\_join\_areas2  
 → select({_, sample\_one(geometry:population, coverage: area2) as area2})  
 → join(on: true) as population\_join\_areas1  
 → select({_, sample\_one(geometry: population, coverage: area1) as area1})  
 → join(on: true) as population\_join\_hazards  
 → select({_, sample\_centroid(geometry: population, coverage: event.coverage) as hazard})  
 → select({_}) as sampled\_population  
 → select({_, consequence: map(hazard, hv → is\_exposed(population, hazard))})  
 → select({\*}) as population\_impact\_table

input(relation: ‘StatisticalArea2’, name: ‘area1’) as areas1\_input  
 → group({to\_coverage(area1) as area1}) as areas1  
 → select({area1}) as areas1\_POP  
areas1\_POP  
 → population\_join\_areas1.rhs

---

<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:** [30 September 2024 20:37 UTC](https://community.riskscape.org.nz/t/pipeline-running-slow-when-area-layer-is-being-used/191/2 "2024-09-30T20:37:41Z")

</div>

Kia ora Rebecca,

1. The latest version of RiskScape (v1.7.0) has a performance optimization for just this case. When building the area-layer coverage, there’s a new `intersection_cut` option, e.g.

2. Another thing to be careful with is using the [‘clipped’ regional boundaries](https://datafinder.stats.govt.nz/layer/111206-statistical-area-2-2023-clipped-generalised/) rather than the [‘generalised’ regional boundaries](https://datafinder.stats.govt.nz/layer/111227-statistical-area-2-2023-generalised/). The generalised boundaries contains an ‘Area Outside Region’ polygon that spans the whole of NZ. This makes the spatial lookup very slow, as this feature’s bounds will match _every_ building in NZ, so RiskScape has to fall back to a more expensive geometry comparison for every lookup. (Using the `intersection_cut` option will also avoid this slowdown, even if you use the generalised layer).

Hope that helps.

Tim

---

<div class="post-metadata">

**Author:** ![rebeccawelsh](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@rebeccawelsh](https://community.riskscape.org.nz/u/rebeccawelsh)\
**Post date:** [30 September 2024 20:49 UTC](https://community.riskscape.org.nz/t/pipeline-running-slow-when-area-layer-is-being-used/191/3 "2024-09-30T20:49:12Z")

</div>

Hi Tim,

Thank you heaps - that is so much faster now!

Rebecca
