diff --git a/examples/tutorial.ipynb b/examples/tutorial.ipynb index b019dac..6d4071c 100644 --- a/examples/tutorial.ipynb +++ b/examples/tutorial.ipynb @@ -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", @@ -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": { diff --git a/harmony/harmony.py b/harmony/harmony.py index 5082064..8dfcb99 100644 --- a/harmony/harmony.py +++ b/harmony/harmony.py @@ -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): @@ -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 (