Skip to content

Commit 2f36946

Browse files
feature: add kml_footprint endpoint
1 parent 82b9dc2 commit 2f36946

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/SearchAPI/application/application.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from copy import copy
23
import json
34

@@ -226,6 +227,26 @@ async def file_to_wkt(files: list[UploadFile]):
226227
headers=constants.DEFAULT_HEADERS
227228
)
228229

230+
@router.get('/services/utils/kml_footprint')
231+
async def kml_to_footprint(request: Request, granule: str, maturity: str = 'prod'):
232+
config = load_config_maturity(maturity=maturity)
233+
234+
query_opts = asf.ASFSearchOptions(granule_list=[granule])
235+
if (auth:=request.headers.get('authorization')) is not None:
236+
session = SearchAPISession()
237+
session.headers.update({'Authorization': auth})
238+
query_opts.session = session
239+
240+
241+
query_opts.host = config['cmr_base']
242+
243+
results = asf.search(opts=query_opts, dataset=asf.DATASET.NISAR)
244+
245+
kml_file = results.find_urls(extension='.kml')[0]
246+
247+
kml_response = query_opts.session.get(kml_file)
248+
return kml_response.text
249+
229250
# example: https://api.daac.asf.alaska.edu/services/redirect/NISAR_L2_STATIC/{granule_id}.h5
230251
# @router.get('/services/redirect/{short_name}/{granule_id}')
231252
# async def nisar_static_layer(short_name: str, granule_id: str):

0 commit comments

Comments
 (0)