Skip to content

Commit

Permalink
draft codes to calculate the area of aoi
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyli92 committed Nov 21, 2024
1 parent 85bbd14 commit a72f3cd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -350,6 +351,11 @@ def get_rainfall_information(scenario_id: int) -> Response:
return make_response(jsonify(medusa_rainfall_dictionary), OK)


# @app.route('/scenarios/medusa/<int:scenario_id>', methods=["GET"])
# @check_celery_alive
# def get_rainfall_information(scenario_id: int) -> Response:


@app.route('/models/<int:model_id>/buildings', methods=["GET"])
@check_celery_alive
def retrieve_building_flood_status(model_id: int) -> Response:
Expand Down
25 changes: 25 additions & 0 deletions src/processes/area.py
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions terriajs/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
Expand Down

0 comments on commit a72f3cd

Please sign in to comment.