@@ -1147,15 +1147,18 @@ def record2json(record, url, collection, mode='ogcapi-records'):
11471147
11481148 # todo; for keywords with a scheme use the theme property
11491149 if record .topicategory :
1150- themes = [ {
1150+ tctheme = {
11511151 'concepts' : [],
11521152 'scheme' : 'https://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_TopicCategoryCode'
1153- }]
1154-
1155- for rtp in record .topicategory :
1156- themes ['concepts' ].append ({'id' : rtp })
1153+ }
11571154
1158- record_dict ['properties' ]['themes' ] = themes
1155+ if isinstance (record .topicategory , list ):
1156+ for rtp in record .topicategory :
1157+ tctheme ['concepts' ].append ({'id' : rtp })
1158+ elif isinstance (record .topicategory , str ):
1159+ tctheme ['concepts' ].append ({'id' : record .topicategory })
1160+
1161+ record_dict ['properties' ]['themes' ] = [tctheme ]
11591162
11601163 if record .otherconstraints :
11611164 if isinstance (record .otherconstraints , str ) and record .otherconstraints not in [None , 'None' ]:
@@ -1226,15 +1229,15 @@ def record2json(record, url, collection, mode='ogcapi-records'):
12261229 record_dict ['properties' ]['contacts' ] = rcnt
12271230
12281231 if record .themes not in [None , '' , 'null' ]:
1229- ogcapi_themes = []
1232+ ogcapi_themes = record_dict [ 'properties' ]. get ( 'themes' , [])
12301233 # For a scheme, prefer uri over label
12311234 # OWSlib currently uses .keywords_object for keywords with url, see https://github.com/geopython/OWSLib/pull/765
12321235 try :
12331236 for theme in json .loads (record .themes ):
12341237 try :
12351238 ogcapi_themes .append ({
1236- 'scheme' : theme ['thesaurus' ].get ('url' , theme ['thesaurus' ].get ('title' , '' ) ),
1237- 'concepts' : [{'id' : c } for c in theme .get ('keywords_object ' , []) if c not in [None , '' ]]
1239+ 'scheme' : theme ['thesaurus' ].get ('url' ) or theme ['thesaurus' ].get ('title' ),
1240+ 'concepts' : [{'id' : c . get ( 'name' , '' ) } for c in theme .get ('keywords ' , []) if 'name' in c and c [ 'name' ] not in [None , '' ]]
12381241 })
12391242 except Exception as err :
12401243 LOGGER .exception (f"failed to parse theme of { record .identifier } : { err } " )
0 commit comments