Skip to content

Commit 227f822

Browse files
author
Tik
committed
geopython#80 - bugfix
1. Provider hateoas.py _modify_content_for_display content['assets'] is None, so the assigment content['assets']['default'] failed. 2. stac.py get_stac_search, empty collection return from get_stac_collection is checked.
1 parent 8f9b17d commit 227f822

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

pygeoapi/api/stac.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,13 @@ def _recursiveCollections(api, request, path):
398398
tmp = []
399399
children = []
400400
for c in queries["collections"]:
401+
# there are 2 possible returns from get_stac_collection,
402+
# if the collection not exists, it return an empty collection list : {'collections': []}
403+
# otherwise, it returns the collection details in json : {'id': 'xxx', 'type': 'Collection', ....}
401404
collect = json.loads(get_stac_collections(api, request, f'collections/{c}')[2])
402-
children += ['collections/' + l['href'].split('/')[-1] for l in collect['links'] if (l.get('entry:type') == 'Collection')]
403-
tmp += [collect] if (len(children) == 0) else []
405+
if (collect.get('collections') is None):
406+
children += ['collections/' + l['href'].split('/')[-1] for l in collect['links'] if (l.get('entry:type') == 'Collection')]
407+
tmp += [collect] if (len(children) == 0) else []
404408
for c in children:
405409
tmp += _recursiveCollections(api, request, c)
406410
queries['collections'] = tmp
@@ -462,15 +466,6 @@ def _recursiveCollections(api, request, path):
462466
result = [r for i, r in enumerate(result) if (i in find_idx)]
463467
result = sorted(result, key=lambda k: k.get(sortby['field'], ''))
464468

465-
# for r in result:
466-
# if (r['assets']['image']['type'] == asset_cogtype):
467-
# try:
468-
# s=r['assets']['image']['href']
469-
# s=urllib.parse.unquote(s)
470-
# s=s.split('?')[0]
471-
# r['assets']['image']['href']="/".join(s.split('/')[7:8]+s.split('/')[9:])
472-
# except KeyError:
473-
# pass
474469
LOGGER.info(f'STAC search filtered results : {len(result)}')
475470
# "context": { "returned":len(result), "limit":"0", "matched":len(find_idx) }
476471
max_items = len(result) if (max_items == -1) else max_items

pygeoapi/provider/hateoas.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,11 @@ def _modify_content_for_display(
352352
353353
:returns: `dict` of JSON item
354354
"""
355-
content['assets']['default'] = {
356-
'href': os.path.join(baseurl, urlpath).replace('\\', '/'),
357-
}
355+
if(content.get('assets') is None):
356+
content['assets']={'default': {
357+
'href': os.path.join(baseurl, urlpath).replace('\\', '/'),
358+
}
359+
}
358360
for key in content['assets']:
359361
content['assets'][key]['file:size'] = 0
360362
try:

0 commit comments

Comments
 (0)