-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create bounding box area calculation process #301
Closed
LukeParky
wants to merge
1
commit into
otakaro_digital_twin
from
256-Draw-Bounding-Box-Calculate-Area
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,14 @@ dependencies: | |
- botocore>=1.33.10 # Minimum version that is compatible with python >= 3.10 is botocore>=1.13.0 | ||
- scrapy==2.11.1 | ||
- gevent==23.9.1 | ||
- pywps==4.6.0 | ||
- pip: | ||
- flask_swagger_ui==4.11.1 | ||
- geovoronoi==0.4.0 | ||
- geoapis==0.3.2 | ||
- celery==5.2.7 | ||
- gunicorn==20.1.0 | ||
- git+https://github.com/LukeParky/[email protected] | ||
- pywps==4.6.0 # pywps is available in conda but our fork of OWSLib is required for bounding boxes | ||
- git+https://github.com/GeospatialResearch/OWSLib.git | ||
|
||
prefix: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||||
# # -*- coding: utf-8 -*- | ||||||||
"""Defines PyWPS WebProcessingService processes for calculating area of geometries.""" | ||||||||
|
||||||||
from geopandas import GeoDataFrame | ||||||||
from pywps import BoundingBoxInput, Process, LiteralOutput, WPSRequest | ||||||||
from pywps.response.execute import ExecuteResponse | ||||||||
from shapely import box | ||||||||
|
||||||||
|
||||||||
class BoundingBoxAreaProcess(Process): | ||||||||
"""Class representing a WebProcessingService process for calculating area of a bounding box""" | ||||||||
|
||||||||
def __init__(self) -> None: | ||||||||
"""Define inputs and outputs of the WPS process, and assogm process handler.""" | ||||||||
# Create bounding box WPS inputs. | ||||||||
inputs = [BoundingBoxInput('bboxin', 'box in', crss=['epsg:4326'])] | ||||||||
# Create area WPS outputs. | ||||||||
outputs = [LiteralOutput('area', 'Area', data_type='string')] | ||||||||
|
||||||||
# Initialise the process. | ||||||||
super().__init__( | ||||||||
self._handler, | ||||||||
identifier='area', | ||||||||
title="Calculate the area of the polygon.", | ||||||||
inputs=inputs, | ||||||||
outputs=outputs, | ||||||||
) | ||||||||
|
||||||||
@staticmethod | ||||||||
def _handler(request: WPSRequest, response: ExecuteResponse) -> None: | ||||||||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
""" | ||||||||
Process handler for calculating bounding box area. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
request : WPSRequest | ||||||||
The WPS request, containing input parameters. | ||||||||
response : ExecuteResponse | ||||||||
The WPS response, containing output data. | ||||||||
""" | ||||||||
# Get coordinates from bounding box input | ||||||||
bounding_box_input = request.inputs['bboxin'][0] | ||||||||
ymin, xmin = bounding_box_input.ll # lower left | ||||||||
ymax, xmax = bounding_box_input.ur # upper right | ||||||||
|
||||||||
# Form bounding box into standard shapely.box | ||||||||
bounding_box = box(xmin, ymin, xmax, ymax) | ||||||||
# Create GeoDataFrame with unit of measurement in metres. | ||||||||
gdf = GeoDataFrame(index=[0], crs="epsg:4326", geometry=[bounding_box]).to_crs(epsg=2193) | ||||||||
|
||||||||
# Calculate area in square metres | ||||||||
area = gdf.geometry[0].area | ||||||||
# Format area | ||||||||
display_area = f"{area:.0f} m²" | ||||||||
response.outputs['area'].data = display_area |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.