Skip to content

Commit

Permalink
enhance STAC collection metadata from non-STAC resources (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis authored Jan 7, 2025
1 parent d597429 commit 8bb5226
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions pycsw/stac/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from pycsw.core.pygeofilter_evaluate import to_filter
from pycsw.ogc.api.oapi import gen_oapi
from pycsw.ogc.api.records import API, build_anytext
from pycsw.core.util import geojson_geometry2bbox
from pycsw.core.util import geojson_geometry2bbox, wkt2geom

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -247,10 +247,9 @@ def collections(self, headers_, args):
virtual_collections = self.repository.query_collections(filters, limit)

for virtual_collection in virtual_collections:
print("VIRTUAL COLLECTION", virtual_collection)
virtual_collection_info = self.get_collection_info(
virtual_collection.identifier,
dict(title=virtual_collection.title,
description=virtual_collection.abstract))
virtual_collection.identifier, virtual_collection)

collections.append(virtual_collection_info)

Expand All @@ -277,12 +276,12 @@ def collections(self, headers_, args):

if not id_found:
LOGGER.debug('Adding STAC collection')
sc2 = sc
sc2.title = sc.title or sc.identifier
sc2.abstract = sc.abstract or sc.identifier
response['collections'].append(self.get_collection_info(
sc.identifier, {
'title': sc.title or sc.identifier,
'description': sc.abstract or sc.identifier
})
)
sc2.identifier, sc2
))

url_base = f"{self.config['server']['url']}/collections"

Expand Down Expand Up @@ -334,9 +333,7 @@ def collection(self, headers_, args, collection='metadata:main'):
try:
virtual_collection = self.repository.query_ids([collection])[0]
collection_info = self.get_collection_info(
virtual_collection.identifier,
dict(title=virtual_collection.title,
description=virtual_collection.abstract))
virtual_collection.identifier, virtual_collection)
except IndexError:
return self.get_exception(
404, headers_, 'InvalidParameterValue', 'STAC collection not found')
Expand Down Expand Up @@ -497,11 +494,21 @@ def get_collection_info(self, collection_name: str = 'metadata:main',
description = self.config['metadata']['identification']['description'] # noqa
else:
id_ = collection_name
title = collection_info.get('title')
description = collection_info.get('description')
title = collection_info.title
description = collection_info.abstract

return {
'id': id_,
'stac_version': '1.0.0',
'license': 'other',
'extent': {
'spatial': {
'bbox': [wkt2geom(collection_info.wkt_geometry)]
},
'temporal': {'interval': [[
collection_info.time_begin, collection_info.time_end
]]}
},
'title': title,
'description': description,
'type': 'Collection',
Expand Down

0 comments on commit 8bb5226

Please sign in to comment.