# 
# RiskScape™ Copyright New Zealand Institute for Earth Science Limited
# (Earth Sciences New Zealand) is distributed for research purposes only
# under the terms of AGPLv3.
# 
# RiskScape™ Copyright 2026 New Zealand Institute for Earth Science
# Limited (Earth Sciences New Zealand). All rights reserved. Source code
# available under the AGPLv3.
# 
# This program is free software: you can redistribute it and/or modify it under
#  the terms of the GNU Affero General Public License as published by the Free
#  Software Foundation, either version 3 of the License, or (at your option) any
#  later version.
# 
# This program is distributed for RESEARCH PURPOSES ONLY, in the hope that it will
# be useful for research and education initiatives.
# 
# If you are not a researcher, or you are a researcher who wishes to use this
# program on terms other than AGPLv3 (including those who wish to restrict the
# distribution of any source code created using this program), please contact:
# https://riskscape.org.nz
# 
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Affero General Public License for more details.  You should have received a copy
# of the GNU Affero General Public License along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
# 
# By way of summary only, under the AGPLv3:
#     • Permissions of this strongest copyleft license are conditioned
#       on making available complete source code of licensed works and
#       modifications, which include larger works using a licensed work,
#       under the same license.
#     • Copyright and license notices must be preserved.
#     • Contributors provide an express grant of patent rights.
#     • When a modified version is used to provide a service over a
#       network, the complete source code of the modified version must be made
#       available.
# 
[project]
description = Example models to demonstrate different geoprocessing functionality
auto-import = true

[bookmark Roads_SE_Upolu]
location = data/Roads_SE_Upolu.shp
set-attribute.width_metres = num_lanes * 3

[bookmark SPT_inundation_50m_grid]
location = data/MaxEnv_All_Scenarios_50m.tif

[bookmark Samoa_regions]
location = data/Samoa_constituencies.shp

[bookmark Only_Falealili]
location = data/Samoa_constituencies.shp
filter = Region = 'Falealili'

[model simple-exposure]
description = Simple exposure model for roads in SE Upolu
framework = wizard
input-exposures.layer = Roads_SE_Upolu
input-exposures.geoprocess = false
input-hazards.layer = SPT_inundation_50m_grid
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = CLOSEST
sample.areas-buffer = 1000
analysis.function = is_exposed
report-event-impact.filter = consequence = 1
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
report-event-impact.aggregate[1] = round(sum(exposure.length)) / 1000 as Exposed_km
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

[model cut-by-distance]
description = Cut the roads into 50m chunks prior to running the model
framework = wizard
input-exposures.layer = Roads_SE_Upolu
input-exposures.geoprocess = true
input-exposures.cut = BY_DISTANCE
input-exposures.cut-distance = 50
input-exposures.recompute[0][attribute] = length
input-exposures.recompute[0][expression] = measure(exposure)
input-exposures.save-raw-results = true
input-hazards.layer = SPT_inundation_50m_grid
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = CLOSEST
sample.areas-buffer = 1000
analysis.function = is_exposed
report-event-impact.filter = consequence = 1
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
report-event-impact.aggregate[1] = round(sum(exposure.length)) / 1000 as Exposed_km
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

[model exposed-length]
description = Calculates the length of road exposed to the hazard using all-intersections/exposed_ratio
framework = wizard
input-exposures.layer = data/Roads_SE_Upolu.shp
input-exposures.geoprocess = false
input-hazards.layer = data/MaxEnv_All_Scenarios_50m.tif
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = ALL_INTERSECTIONS
sample.areas-buffer = 1000
analysis.aggregate-hazards = false
analysis.aggregate-consequences = true
analysis.aggregate-consequences-function = sum
analysis.scale-losses = false
analysis.function = is_exposed
analysis.save-raw-results = true
report-event-impact.filter = consequence > 0
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
# here the consequence is the ratio of the road that was exposed to the hazard
report-event-impact.aggregate[1] = round(sum(exposed_ratio * exposure.length)) / 1000 as Exposed_km
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

[model cut-by-layer]
description = Similar to exposed-length, but cuts the roads by regional boundaries beforehand
framework = wizard
input-exposures.layer = Roads_SE_Upolu
input-exposures.geoprocess = true
input-exposures.cut = BY_LAYER
input-exposures.cut-by-layer = Samoa_regions
input-exposures.cut-by-layer-include = ALL_PARTS
input-exposures.recompute[0][attribute] = length
input-exposures.recompute[0][expression] = measure(exposure)
input-exposures.save-raw-results = true
input-hazards.layer = SPT_inundation_50m_grid
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = ALL_INTERSECTIONS
sample.areas-buffer = 1000
analysis.aggregate-hazards = false
analysis.aggregate-consequences = true
analysis.aggregate-consequences-function = sum
analysis.scale-losses = false
analysis.function = is_exposed
report-event-impact.filter = consequence > 0
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
report-event-impact.aggregate[1] = round(sum(exposed_ratio * exposure.length)) / 1000 as Exposed_km
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

[model filter-by-region]
description = Only includes roads that intersect Falealili region in the model
framework = wizard
input-exposures.layer = Roads_SE_Upolu
input-exposures.geoprocess = true
input-exposures.filter = BY_FEATURE_IN_LAYER
input-exposures.filter-layer = Samoa_regions
input-exposures.filter-layer-condition = Region = 'Falealili'
input-exposures.save-raw-results = true
input-hazards.layer = SPT_inundation_50m_grid
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = ALL_INTERSECTIONS
sample.areas-buffer = 1000
analysis.aggregate-hazards = false
analysis.aggregate-consequences = true
analysis.aggregate-consequences-function = sum
analysis.scale-losses = false
analysis.function = is_exposed
report-event-impact.filter = consequence > 0
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
report-event-impact.aggregate[1] = round(sum(exposed_ratio * exposure.length)) / 1000 as Exposed_km
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

[model include-only-region]
description = Similar to filter-by-region, but has a hard cut-off on the regional boundary
framework = wizard
input-exposures.layer = Roads_SE_Upolu
input-exposures.geoprocess = true
input-exposures.cut = BY_LAYER
input-exposures.cut-by-layer = Only_Falealili
input-exposures.cut-by-layer-include = ONLY_INTERSECTIONS
input-exposures.recompute[0][attribute] = length
input-exposures.recompute[0][expression] = measure(exposure)
input-exposures.save-raw-results = true
input-hazards.layer = SPT_inundation_50m_grid
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = ALL_INTERSECTIONS
sample.areas-buffer = 1000
analysis.aggregate-hazards = false
analysis.aggregate-consequences = true
analysis.aggregate-consequences-function = sum
analysis.scale-losses = true
analysis.function = is_exposed
report-event-impact.filter = consequence > 0
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
report-event-impact.aggregate[1] = round(sum(consequence * exposure.length)) / 1000 as Exposed_km
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

[model buffer-roads]
description = Enlarges the roads before running the model
framework = wizard
input-exposures.layer = Roads_SE_Upolu
input-exposures.geoprocess = true
input-exposures.enlarge = true
input-exposures.enlarge-by[mode] = MITRED_FLAT
input-exposures.enlarge-by[remove-overlaps] = false
input-exposures.enlarge-by[distance] = exposure.width_metres / 2
input-exposures.save-raw-results = true
input-hazards.layer = SPT_inundation_50m_grid
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = ALL_INTERSECTIONS
sample.areas-buffer = 1000
analysis.aggregate-hazards = false
analysis.aggregate-consequences = true
analysis.aggregate-consequences-function = sum
analysis.scale-losses = false
analysis.function = is_exposed
report-event-impact.filter = consequence > 0
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
report-event-impact.aggregate[1] = round(sum(exposure.length)) / 1000 as Exposed_km
report-event-impact.aggregate[2] = round(sum(exposed_ratio * measure(exposure))) as Exposed_m2
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

[model buffer-no-overlap]
description = Enlarges roads and removes any resulting overlaps
framework = wizard
input-exposures.layer = Roads_SE_Upolu
input-exposures.geoprocess = true
input-exposures.enlarge = true
input-exposures.enlarge-by[mode] = MITRED_FLAT
input-exposures.enlarge-by[remove-overlaps] = true
input-exposures.enlarge-by[distance] = exposure.width_metres / 2
input-exposures.save-raw-results = true
input-hazards.layer = SPT_inundation_50m_grid
input-areas.layer = Samoa_regions
input-areas.geoprocess = false
sample.hazards-by = ALL_INTERSECTIONS
sample.areas-buffer = 1000
analysis.aggregate-hazards = false
analysis.aggregate-consequences = true
analysis.aggregate-consequences-function = sum
analysis.scale-losses = false
analysis.function = is_exposed
report-event-impact.filter = consequence > 0
report-event-impact.group-by[0] = area.Region
report-event-impact.aggregate[0] = count(exposure) as Exposed_segments
report-event-impact.aggregate[1] = round(sum(exposure.length)) / 1000 as Exposed_km
report-event-impact.aggregate[2] = round(sum(exposed_ratio * measure(exposure))) as Exposed_m2
report-event-impact.sort-by[0][attribute] = Region
report-event-impact.sort-by[0][direction] = ASC

