Skip to content
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

HARMONY-1859: Add WKT POINT support in harmony-py. #94

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
"request = Request(\n",
" collection=collection,\n",
" spatial=WKT('POLYGON((-140 20, -50 20, -50 60, -140 60, -140 20))'),\n",
" # spatial=WKT('POINT(-40 10)'),\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if commented out code is likely to confuse people - maybe we could link to read-the-docs in a cell instead that shows an example of all of the supported WKT spatial strings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated documentation.

" granule_id=['C1233800302-EEDTEST'],\n",
" max_results=1,\n",
" temporal={\n",
Expand Down Expand Up @@ -384,6 +385,14 @@
" if filename.endswith(\"png\"):\n",
" helper.show_result(filename)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09f132f3-6117-4ca0-b2b6-ae41c6b48981",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
16 changes: 15 additions & 1 deletion harmony/harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,20 @@ def _http_method(self, request: BaseRequest) -> str:
method = 'GET' if isinstance(request, CapabilitiesRequest) else 'POST'
return method

def _wkt_to_edr_route(self, wkt_string: str) -> str:
"""Returns the EDR route for the given WKT string."""
# Load the WKT string into a Shapely geometry object
geometry = loads(wkt_string)

if geometry.geom_type == 'Polygon' or geometry.geom_type == 'MultiPolygon':
return 'area'
elif geometry.geom_type == 'Point' or geometry.geom_type == 'MultiPoint':
return 'position'
elif geometry.geom_type == 'LineString' or geometry.geom_type == 'MultiLineString':
return 'trajectory'
else:
raise Exception(f"Unsupported geometry type: {geometry.geom_type}")

def _submit_url(self, request: BaseRequest) -> str:
"""Constructs the URL for the request that is used to submit a new Harmony Job."""
if isinstance(request, CapabilitiesRequest):
Expand All @@ -616,7 +630,7 @@ def _submit_url(self, request: BaseRequest) -> str:
f'{self.config.root_url}'
f'/ogc-api-edr/1.1.0/collections'
f'/{request.collection.id}'
f'/area'
f'/{self._wkt_to_edr_route(request.spatial.wkt)}'
)
else:
return (
Expand Down