From a72f3cd28c861722db9ebd8d6ace8bdfe4ad779d Mon Sep 17 00:00:00 2001 From: Casey Li Date: Thu, 21 Nov 2024 15:47:40 +1300 Subject: [PATCH] draft codes to calculate the area of aoi --- src/app.py | 8 +++++++- src/processes/area.py | 25 +++++++++++++++++++++++++ terriajs/catalog.json | 9 +++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/processes/area.py diff --git a/src/app.py b/src/app.py index 824e5c15..6075597f 100644 --- a/src/app.py +++ b/src/app.py @@ -19,6 +19,7 @@ from src import tasks from src.config import EnvVariable from src.pollution_model.medusa_process_service import MedusaProcessService +from src.processes.area import AreaProcessService # Initialise flask server object app = Flask(__name__) @@ -82,7 +83,7 @@ def decorated_function(*args: Tuple, **kwargs: Dict) -> Response: app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL) processes = [ - MedusaProcessService() + MedusaProcessService(), AreaProcessService() ] process_descriptor = {process.identifier: process.abstract for process in processes} @@ -350,6 +351,11 @@ def get_rainfall_information(scenario_id: int) -> Response: return make_response(jsonify(medusa_rainfall_dictionary), OK) +# @app.route('/scenarios/medusa/', methods=["GET"]) +# @check_celery_alive +# def get_rainfall_information(scenario_id: int) -> Response: + + @app.route('/models//buildings', methods=["GET"]) @check_celery_alive def retrieve_building_flood_status(model_id: int) -> Response: diff --git a/src/processes/area.py b/src/processes/area.py new file mode 100644 index 00000000..57dd4e19 --- /dev/null +++ b/src/processes/area.py @@ -0,0 +1,25 @@ +# # -*- coding: utf-8 -*- + +from pywps import Process, BoundingBoxInput, BoundingBoxOutput + + +class AreaProcessService(Process): + def __init__(self): + inputs = [BoundingBoxInput('bboxin', 'box in', crss=['epsg:4326'])] + outputs = [BoundingBoxOutput('bboxout', 'box out', crss=['epsg:4326'])] + # outputs = [ComplexOutput("bboxout", "box out", supported_formats=[Format('JSON')])] + + super().__init__( + self._handler, + identifier='area', + title="Calculate the area of the polygon.", + inputs=inputs, + outputs=outputs, + store_supported=True, + status_supported=True + ) + + def _handler(self, request, response): + response.outputs['bboxout'].data = request.inputs['bboxin'][0].data + return response + diff --git a/terriajs/catalog.json b/terriajs/catalog.json index 10e93bdd..b7317db2 100644 --- a/terriajs/catalog.json +++ b/terriajs/catalog.json @@ -195,6 +195,15 @@ "url": "http://localhost:5000/wps", "identifier": "medusa", "storeSupported": true + }, + { + "type": "wps", + "name": "Area", + "description": "Calculate the area of the polygon.", + "url": "http://localhost:5000/wps", + "identifier": "area", + "storeSupported": true, + "statusSupported": true } ] }