Pipeline running slow when area layer is being used

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

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.

    → group({to_coverage(area1, { intersection_cut: true }) as area1}) as areas1
    

    Basically this new option cuts the large irregular regional boundaries into smaller, more uniform polygons, which makes the spatial look-up operation a lot faster (without any change to the geometry returned by the lookup).

  2. Another thing to be careful with is using the ‘clipped’ regional boundaries rather than the ‘generalised’ regional boundaries. 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

Hi Tim,

Thank you heaps - that is so much faster now!

Rebecca