Skip to content

Commit

Permalink
Use GeoShape box rather than polygon
Browse files Browse the repository at this point in the history
It's simpler and corresponds directly with the bounding box representation of all our spatial extents.

ref SAEON/mims-catalog#1
  • Loading branch information
marksparkza committed Nov 9, 2023
1 parent c55ed74 commit 9e019f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 12 additions & 8 deletions odp/catalog/mims.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def evaluate_record(
cannot_publish_reasons += ['not a MIMS collection']

def create_published_record(self, record_model: RecordModel) -> PublishedRecordModel:
"""Create the published form of a record."""
published_record: PublishedSAEONRecordModel = super().create_published_record(record_model)

# add related identifiers for published child records to
Expand Down Expand Up @@ -74,6 +75,7 @@ def create_published_record(self, record_model: RecordModel) -> PublishedRecordM
def _create_jsonld_metadata(
self, published_record: PublishedSAEONRecordModel
) -> dict[str, Any]:
"""Create a JSON-LD metadata dictionary, using the schema.org vocabulary."""
mims_catalog = Session.get(Catalog, self.catalog_id)
datacite_metadata = self._get_metadata_dict(published_record, ODPMetadataSchema.SAEON_DATACITE4)

Expand Down Expand Up @@ -110,23 +112,25 @@ def _create_jsonld_metadata(
"url": url,
}

if box := next(
# Create a GeoShape box from DataCite geoLocationBox, because currently
# we only use bounding boxes in our metadata. If in future we ever use
# geoLocationPolygons, then this code will need to be adapted.
if geolocation_box := next(
(g.get('geoLocationBox') for g in datacite_metadata.get('geoLocations', ())),
None
):
polygon = (
f'{box["southBoundLatitude"]},{box["westBoundLongitude"]} '
f'{box["southBoundLatitude"]},{box["eastBoundLongitude"]} '
f'{box["northBoundLatitude"]},{box["eastBoundLongitude"]} '
f'{box["northBoundLatitude"]},{box["westBoundLongitude"]} '
f'{box["southBoundLatitude"]},{box["westBoundLongitude"]}'
box = (
f'{geolocation_box["southBoundLatitude"]} '
f'{geolocation_box["westBoundLongitude"]} '
f'{geolocation_box["northBoundLatitude"]} '
f'{geolocation_box["eastBoundLongitude"]}'
)
jsonld_metadata |= {
"spatialCoverage": {
"@type": "Place",
"geo": {
"@type": "GeoShape",
"polygon": polygon
"box": box,
},
},
}
Expand Down
4 changes: 1 addition & 3 deletions test/api/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ def test_redirect_to(
metadata_examples = {
'SAEON.DataCite4': datacite4_example(),
'SAEON.ISO19115': iso19115_example(),
}
metadata_examples |= {
'SchemaOrg.Dataset': {
'@context': 'https://schema.org/',
'@type': 'Dataset',
Expand All @@ -229,7 +227,7 @@ def test_redirect_to(
'@type': 'Place',
'geo': {
'@type': 'GeoShape',
'polygon': '-34.4,17.9 -34.4,18.3 -34.0,18.3 -34.0,17.9 -34.4,17.9'
'box': '-34.4 17.9 -34.0 18.3',
}
}
},
Expand Down

0 comments on commit 9e019f7

Please sign in to comment.