Skip to content

Commit 6c1bc61

Browse files
committed
Add JSON-LD context to STAC resources
1 parent 03110b1 commit 6c1bc61

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pygeoapi/api/stac.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
)
5757
from pygeoapi.util import (
5858
filter_dict_by_key_value, get_current_datetime, get_provider_by_type,
59-
render_j2_template, to_json
59+
render_j2_template, to_json, get_base_url
6060
)
6161

6262
from . import APIRequest, API, FORMAT_TYPES, F_JSON, F_HTML
@@ -200,6 +200,8 @@ def get_stac_path(api: API, request: APIRequest,
200200
content['links'].extend(
201201
stac_collections[dataset].get('links', []))
202202

203+
linked_data = api.config['resources'][dataset].get('linked-data')
204+
203205
if request.format == F_HTML: # render
204206
content['path'] = path
205207
if 'assets' in content: # item view
@@ -227,6 +229,18 @@ def get_stac_path(api: API, request: APIRequest,
227229

228230
return headers, HTTPStatus.OK, content
229231

232+
elif (linked_data
233+
and all(linked_data.get(k)
234+
for k in ('context', 'inject_verbatim_context'))):
235+
content = {
236+
'@context': linked_data['context'],
237+
**content
238+
}
239+
if replace_id_field := linked_data.get('replace_id_field'):
240+
content[replace_id_field] = (f"{get_base_url(api.config)}"
241+
f"/stac/{path}")
242+
pass
243+
230244
return headers, HTTPStatus.OK, to_json(content, api.pretty_print)
231245

232246
else: # send back file

0 commit comments

Comments
 (0)