Skip to content

Commit e88d476

Browse files
committed
Fix missing links in items and item id
1 parent 545f2c8 commit e88d476

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

pygeoapi/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
'http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections',
110110
'http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/landing-page',
111111
'http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/json',
112-
'http://www.opengis.net/spec/json-fg-1/0.2/conf/core',
112+
'http://www.opengis.net/spec/json-fg-1/0.3/conf/core',
113113
'http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/oas30'
114114
]
115115

pygeoapi/api/itemtypes.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,10 @@ def get_collection_items(
710710

711711
try:
712712
content = formatter.write(
713+
api=api,
713714
data=content,
715+
dataset=dataset,
716+
id_field=(p.uri_field or 'id'),
714717
options={
715718
'provider_def': get_provider_by_type(
716719
collections[dataset]['providers'],
@@ -723,7 +726,9 @@ def get_collection_items(
723726
HTTPStatus.INTERNAL_SERVER_ERROR, headers, request.format,
724727
'NoApplicableCode', msg)
725728

726-
return headers, HTTPStatus.OK, content
729+
headers['Content-Type'] = formatter.mimetype
730+
731+
return headers, HTTPStatus.OK, to_json(content, api.pretty_print)
727732

728733
return headers, HTTPStatus.OK, to_json(content, api.pretty_print)
729734

@@ -947,6 +952,11 @@ def get_collection_item(api: API, request: APIRequest,
947952
'title': l10n.translate('This document as JSON', request.locale),
948953
'href': f'{uri}?f={F_JSON}'
949954
}, {
955+
'rel': request.get_linkrel(F_JSONFG),
956+
'type': FORMAT_TYPES[F_JSONFG],
957+
'title': l10n.translate('This document as JSON-FG (JSON-FG)', request.locale), # noqa
958+
'href': f'{uri}?f={F_JSONFG}'
959+
}, {
950960
'rel': request.get_linkrel(F_JSONLD),
951961
'type': FORMAT_TYPES[F_JSONLD],
952962
'title': l10n.translate('This document as RDF (JSON-LD)', request.locale), # noqa
@@ -1010,15 +1020,15 @@ def get_collection_item(api: API, request: APIRequest,
10101020
return headers, HTTPStatus.OK, content
10111021

10121022
elif request.format == F_JSONFG:
1013-
# content = geojson2jsonfg(
1014-
# api, content, dataset, id_field=(p.uri_field or 'id')
1015-
# )
10161023
formatter = load_plugin('formatter',
10171024
{'name': F_JSONFG, 'geom': True})
10181025

10191026
try:
10201027
content = formatter.write(
1028+
api=api,
10211029
data=content,
1030+
dataset=dataset,
1031+
id_field=(p.uri_field or 'id'),
10221032
options={
10231033
'provider_def': get_provider_by_type(
10241034
collections[dataset]['providers'],
@@ -1031,7 +1041,7 @@ def get_collection_item(api: API, request: APIRequest,
10311041
HTTPStatus.INTERNAL_SERVER_ERROR, headers, request.format,
10321042
'NoApplicableCode', msg)
10331043

1034-
return headers, HTTPStatus.OK, content
1044+
return headers, HTTPStatus.OK, to_json(content, api.pretty_print)
10351045

10361046
return headers, HTTPStatus.OK, to_json(content, api.pretty_print)
10371047

pygeoapi/formatter/jsonfg.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from osgeo import gdal
3939

4040
from pygeoapi.formatter.base import BaseFormatter, FormatterSerializationError
41+
from pygeoapi.api import APIRequest
4142

4243
LOGGER = logging.getLogger(__name__)
4344

@@ -61,7 +62,10 @@ def __init__(self, formatter_def: dict):
6162
super().__init__({"name": "jsonfg", "geom": geom})
6263
self.mimetype = "application/geo+json"
6364

64-
def write(self, data: dict, options: dict = {}) -> str:
65+
def write(
66+
self, api: APIRequest, data: dict,
67+
dataset: str, id_field: str, options: dict = {}
68+
) -> dict:
6569
"""
6670
Generate data in JSON-FG format
6771
@@ -78,12 +82,14 @@ def write(self, data: dict, options: dict = {}) -> str:
7882
fields = data["properties"].keys()
7983
except IndexError:
8084
LOGGER.error("no features")
81-
return str()
85+
return dict()
8286

8387
LOGGER.debug(f"JSONFG fields: {fields}")
8488

8589
try:
86-
output = geojson2jsonfg(data=data, dataset="items")
90+
links = data.get("links")
91+
output = geojson2jsonfg(data=data, dataset=dataset)
92+
output["links"] = links
8793
return output
8894
except ValueError as err:
8995
LOGGER.error(err)
@@ -98,18 +104,17 @@ def geojson2jsonfg(
98104
dataset: str,
99105
identifier: Union[str, None] = None,
100106
id_field: str = "id",
101-
) -> str:
107+
) -> dict:
102108
"""
103109
Return JSON-FG from a GeoJSON content.
104110
105111
:param cls: API object
106112
:param data: dict of data:
107113
108-
:returns: string of rendered JSON (JSON-FG)
114+
:returns: dict of converted GeoJSON (JSON-FG)
109115
"""
110116
gdal.UseExceptions()
111117
LOGGER.debug("Dump GeoJSON content into a data source")
112-
# breakpoint()
113118
try:
114119
with gdal.OpenEx(json.dumps(data)) as srcDS:
115120
tmpfile = f"/vsimem/{uuid.uuid1()}.json"

0 commit comments

Comments
 (0)