Skip to content

Commit b281f9b

Browse files
authored
Further Fixes for STAC Search (#2340)
* Fix STAC search endpoint reference This mistakenly used double slashes in the URL which would break the output. A single slash fixes this. Closes #2354 * Assets should be dict, not list As specified in the STAC spec: https://stacspec.org/en/about/stac-spec/ assets are dicts, not lists. When missing, now they are initialized as the correct empty data structures. Closes #2354 * Correctly initialize temporal instant Previously the `datetime` field was not used to initalize the temporal instant, causing it to be overridden by other approximations. This ensure that the initialization happens correctly, and the overrides only occur in cases when `datetime` is None. Closes #2356
1 parent 4eaef8e commit b281f9b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

pygeoapi/api/stac.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def landing_page(api: API,
284284
'rel': 'search',
285285
'type': FORMAT_TYPES[F_JSON],
286286
'title': l10n.translate('STAC API search', request.locale),
287-
'href': f"{api.base_url}/stac-api//search?f={F_JSON}"
287+
'href': f"{api.base_url}/stac-api/search?f={F_JSON}"
288288
}]
289289

290290
return headers, status, to_json(content, api.pretty_print)
@@ -379,9 +379,11 @@ def search(api: API, request: Union[APIRequest, Any]) -> Tuple[dict, int, str]:
379379
geom = from_geojson(json.dumps(feature['geometry']))
380380
feature['bbox'] = geom.bounds
381381

382-
for la in ['links', 'assets']:
383-
if feature.get(la) is None:
384-
feature[la] = []
382+
if feature.get('links') is None:
383+
feature['links'] = []
384+
385+
if feature.get('assets') is None:
386+
feature['assets'] = {}
385387

386388
stac_api_response['numberReturned'] = len(stac_api_response['features'])
387389

@@ -488,18 +490,20 @@ def get_temporal(feature: dict) -> dict:
488490
if datetime_ is None and None not in [start_datetime, end_datetime]:
489491
LOGGER.debug('Temporal range partially exists')
490492
elif datetime_ is not None:
493+
value['datetime'] = datetime_
491494
LOGGER.debug('Temporal instant exists')
492495

493496
LOGGER.debug('Attempting to derive temporal from GeoJSON feature')
494497
LOGGER.debug(feature)
495-
if feature.get('time') is not None:
498+
if value.get('datetime') is None and feature.get('time') is not None:
496499
if feature['time'].get('timestamp') is not None:
497500
value['datetime'] = feature['time']['timestamp']
498501
if feature['time'].get('interval') is not None:
499502
value['start_datetime'] = feature['time']['interval'][0]
500503
value['end_datetime'] = feature['time']['interval'][1]
501504

502-
if feature['properties'].get('created') is not None:
505+
if value.get('datetime') is None \
506+
and feature['properties'].get('created') is not None:
503507
value['datetime'] = feature['properties']['created']
504508

505509
if not value:

0 commit comments

Comments
 (0)