nens / lizard-qgis-plugin

A QGIS Lizard plugin
GNU General Public License v3.0
0 stars 0 forks source link

Analyse flood risk for buildings #36

Open leendertvanwolfswinkel opened 2 months ago

leendertvanwolfswinkel commented 2 months ago

UI

  1. Add a "Flood risk buildings button" to the Simulation results tab

    image.png
  2. Enable the button if the scenario contains a result with the result code depth-max-dtri and/or s1-max-dtri.

  3. When the user clicks the button, show a dialog where they can fill in the following inputs:

    • Method: DGBC (default) or Advanced. DGBC should only be available if the scenario contains a result with result code depth-max-dtri. Advanced should be available only when there is a s1-max-dtri result
    • Buildings: Polygon vector layer.
    • Floor level column: only enable this option if Method is Advanced. User should be able to choose any float column present in the selected layer. Automatically switch to "floor_level" if that column is available.
    • Output format: GeoPackage (default) or GeoJSON.
  4. OK/Cancel buttons

API requests / workflow

  1. Save the selected buildings to a geopackage, in a layer that has a field "floor_level" that is a copy of the column that the user indicated they want to use as floor level.

  2. Create a "buildings" result object for the scenario

    curl -u "__key__:<API_TOKEN>" -d '{"name": "buildings", "code": "buildings", "family": "Raw"}' --header "Content-Type: application/json" https://nxt3.staging.lizard.net/api/v4/scenarios/<SCENARIO_UUID>/results/
  3. The buildings result object for the scenario will now contain an _uploadurl . The building features need to be uploaded to this url:

    curl -T test-buildings.gpkg "<UPLOAD_URL>"
  4. Create an object to store the outputs to (a "vulnerable buildings" object) for this scenario

    curl -u "__key__:<API_TOKEN>" -d '{"name": "vulnerable_buildings", "code": "vulnerable_buildings", "family": "Vulnerable_Buildings"}' --header "Content-Type: application/json" https://nxt3.staging.lizard.net/api/v4/scenarios/<SCENARIO_UUID>/results/
  5. Start processingof the vulnerable_buildings result

    curl -u "__key__:<API_TOKEN>" -d '{"method": "advanced"}' --header "Content-Type: application/json" https://nxt3.staging.lizard.net/api/v4/scenarios/<SCENARIO_UUID>/results/<RESULT_ID>/process
  6. Track the progress

    https://nens.lizard.net/api/v4/tasks/<TASK UUID>/

When the processing is finished

Once the processing is finished, refresh the "downloadable files" list. The vulnerable buildings result should appear in the list

ldebek commented 1 month ago

@leendertvanwolfswinkel Few questions:

  1. Is method name (DGBC or Advanced) should be passed somewhere within the API call or distinction is only definded by the "floor_level" column presence?
  2. Where "total_rain_mm": 42 paylod for the start processing call comes from? Could you please elaborate it?
leendertvanwolfswinkel commented 1 month ago

@benvanbasten-ns I think you created these endpoints, right? Can you help out @ldebek please

benvanbasten-ns commented 1 month ago

Hi @ldebek

1 The method name should be passed in the \process api call. It should either be "dgbc" or "advanced". I changed the API description in this issue The output format (gpkg or geojson) can also be passed to the API (output_format: gpkg (default) or geojson), just like method.

2 total_rain_mm is no longer required.

As for the floor_level. In case the method is "advanced", the buildings geopackage should contain a "floor_level" attribute.

Regarding the floor level column: this is not configurable in the backend. This column with this particular name should be added in the frontend, if necessary.

ldebek commented 1 month ago

@benvanbasten-ns Thanks for clarification. I have one more question - is RESULT_ID in the process endpoint refers to the buildingsresult or vulnerable_buildings?

benvanbasten-ns commented 1 month ago

@ldebek Good question. That refers to the vulnerable_buildings result.

ldebek commented 1 month ago

@benvanbasten-ns Thanks - one more request. It seems I don't have an access to the staging Lizard (https://nxt3.staging.lizard.net/) - could you please sort that out for me? 😃

benvanbasten-ns commented 1 month ago

@ldebek I think I can. Did you receive an invitation mail?

ldebek commented 1 month ago

@benvanbasten-ns Unfortunately not.

benvanbasten-ns commented 1 month ago

@ldebek And now ?

ldebek commented 1 month ago

@benvanbasten-ns Got it - thanks! P.S. Cannot obtain API key

benvanbasten-ns commented 1 month ago

@ldebek Ok, I've given you the right permissions, I think. You should be able to go to https://nxt3.staging.lizard.net/ -> management -> personal api keys

ldebek commented 1 month ago

@benvanbasten-ns All works great now - thanks again! :)

ldebek commented 1 month ago

Hi @benvanbasten-ns . I have a problem with creating new result for buildings. Getting 403 code during attempt of POST request to https://nxt3.staging.lizard.net/api/v4/scenarios/9b385b9f-2f85-459d-9c2d-0942d78b836a/results/ with {"name": "buildings", "code": "buildings", "family": "Raw"} data. Response message is: {"status":403,"code":10,"message":"Permission denied. #403.10","detail":"You do not have permission to perform this action."} Am I missing something or is it just an insufficient access rights issue?

benvanbasten-ns commented 1 month ago

@ldebek Sorry voor de late response. I've changed your permission. I think you should be able to do it now.

ldebek commented 1 month ago

@benvanbasten-ns Thanks Ben. I have another question now - is there a way to remove/overwrite previously created 'buildings' result? EDIT: I was able to call DELETE method on buildings result and it's not listed in the scenario results... but while trying to recreate buildings result I'm getting 400 code with following message: Per scenario, a result's code must be unique.

benvanbasten-ns commented 1 month ago

@ldebek Yes, that's expected behavior. When you delete something, I becomes marked for deletion (and hidden), and will be deleted after X days. Unfortunately, it will remain in the database for that period... I'll check if I can delete it from the DB

benvanbasten-ns commented 1 month ago

@ldebek for which scenario are you trying to recreate the result?

ldebek commented 1 month ago

@benvanbasten-ns This one: https://nxt3.staging.lizard.net/api/v4/scenarios/9b385b9f-2f85-459d-9c2d-0942d78b836a/ . Btw. I'm wondering how to best handle case if processing of the buildings fails for some user and user would like to retry whole workflow? Any hints how should it be done to avoid waiting for deleting from DB to happen?

benvanbasten-ns commented 1 month ago

@ldebek I could not find a buildings result in this scenario. Could it be that it has been cleaned up already? Can you try again?

We are currently thinking about ways to avoid the problem you mention.

ldebek commented 1 month ago

@leendertvanwolfswinkel @benvanbasten-ns I've implemented requested functionality, with limitation for cases if user want to re-run analysis for the same scenario. Even if plugin is deleting existing buildingsand vulnerable_buildings results for the scenario, process still will fail with a message saying that those 2 results still exist. In such case user have to wait untill results will be actually deleted on the server and re-run the analysis.