Skip to content

Commit

Permalink
Add flood depth raster
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeParky committed Feb 4, 2025
1 parent 0b843e8 commit b885ecf
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions floodresilience/flood_model/flood_scenario_process_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def __init__(self) -> None:
]
# Create area WPS outputs
outputs = [
ComplexOutput("floodedBuildings", "Flooded Buildings",
ComplexOutput("floodDepth", "Maximum Flood Depth",
supported_formats=[Format("application/vnd.terriajs.catalog-member+json")]),
ComplexOutput("floodedBuildings", "Flooded Buildings",
supported_formats=[Format("application/vnd.terriajs.catalog-member+json")])
]

# Initialise the process
Expand Down Expand Up @@ -91,10 +93,13 @@ def _handler(request: WPSRequest, response: ExecuteResponse) -> None:
"add_vlm": cast_str_to_bool(request.inputs["addVlm"][0].data)
}

modelling_task = tasks.create_model_for_area(bounding_box.wkt, scenario_options)
scenario_id = modelling_task.get()
# modelling_task = tasks.create_model_for_area(bounding_box.wkt, scenario_options)
# scenario_id = modelling_task.get()

scenario_id = 26

# Add Geoserver JSON Catalog entries to WPS response for use by Terria
response.outputs['floodDepth'].data = json.dumps(flood_depth_catalog(scenario_id))
response.outputs['floodedBuildings'].data = json.dumps(building_flood_status_catalog(scenario_id))


Expand Down Expand Up @@ -164,3 +169,29 @@ def building_flood_status_catalog(scenario_id: int) -> dict:
}],
"activeStyle": "is_flooded"
}


def flood_depth_catalog(scenario_id: int) -> dict:
"""
Creates a dictionary in the format of a terria js catalog json for the flood depth layer.
Parameters
----------
scenario_id : int
The ID of the scenario to create the catalog item for.
Returns
----------
dict
The TerriaJS catalog item JSON for the flood depth layer.
"""
gs_flood_model_workspace = f"{EnvVar.POSTGRES_DB}-dt-model-outputs"
gs_flood_url = f"{EnvVar.GEOSERVER_HOST}:{EnvVar.GEOSERVER_PORT}/geoserver/{gs_flood_model_workspace}/ows"

return {
"type": "wms",
"name": "Flood Depth",
"url": gs_flood_url,
"layers": f"{gs_flood_model_workspace}:output_{scenario_id}",
"styles": "viridis_raster"
}

0 comments on commit b885ecf

Please sign in to comment.