Skip to content

Commit

Permalink
OARec: output values if they exist (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis authored Feb 4, 2025
1 parent 5c6015c commit 9eab7a6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pygeometa/schemas/ogcapi_records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
record = {
'id': mcf['metadata']['identifier'],
'conformsTo': [
'http://www.opengis.net/spec/ogcapi-records-1/1.0/req/record-core', # noqa
'http://www.opengis.net/spec/ogcapi-records-1/1.0/conf/record-core', # noqa
],
'type': 'Feature',
'geometry': {
Expand All @@ -116,14 +116,16 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
'title': title[0],
'description': description[0],
'themes': [],
'language': {
'code': self.lang1
},
'type': mcf['metadata']['hierarchylevel'],
},
'links': []
}

if self.lang1 is not None:
record['properties']['language'] = {
'code': self.lang1
}

LOGGER.debug('Checking for temporal')
try:
begin = mcf['identification']['extents']['temporal'][0]['begin']
Expand All @@ -141,6 +143,8 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:

if [begin, end] == [None, None]:
record['time'] = None
elif [begin, end] == ['..', '..']:
pass
else:
record['time'] = {
'interval': [begin, end]
Expand Down Expand Up @@ -214,6 +218,9 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
if all_keywords:
record['properties']['keywords'] = all_keywords

if not record['properties']['themes']:
_ = record['properties'].pop('themes', None)

LOGGER.debug('Checking for licensing')
if mcf['identification'].get('license') is not None:
license = mcf['identification']['license']
Expand Down Expand Up @@ -388,10 +395,12 @@ def generate_link(self, distribution: dict) -> dict:
name = get_charstring(distribution.get('name'), self.lang1, self.lang2)

link = {
'href': distribution['url'],
'type': distribution['type']
'href': distribution['url']
}

if distribution.get('type') is not None:
link['type'] = distribution['type']

reltype = distribution.get('rel') or distribution.get('function')
if reltype is not None:
link['rel'] = reltype
Expand Down

0 comments on commit 9eab7a6

Please sign in to comment.