Skip to content

Commit

Permalink
HARMONY-1859: Add WKT POINT support in harmony-py.
Browse files Browse the repository at this point in the history
  • Loading branch information
ygliuvt committed Sep 6, 2024
1 parent 16280f8 commit 0d5ccda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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",
" 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

0 comments on commit 0d5ccda

Please sign in to comment.