Skip to content

Commit

Permalink
Extend granule items with CMR extension
Browse files Browse the repository at this point in the history
This adds native CMR data to the items to assist with getting back to the
original data within CMR.
  • Loading branch information
Jay Barra committed Oct 10, 2024
1 parent 4d7bd23 commit 4ebbd83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/domains/__tests__/items.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ describe("granuleToStac", () => {
type: "Feature",
id: baseGranule.title,
stac_version: "1.0.0",
stac_extensions: [],
stac_extensions: [
"https://stac-extensions.github.io/cmr/v0.0.0/schema.json"
],
geometry: {
type: "Polygon",
coordinates: [
Expand All @@ -37,6 +39,9 @@ describe("granuleToStac", () => {
},
bbox: [-26.1081458, 29.8680955, -11.4859874, 40.0118589],
properties: {
"cmr:collection_id": "C123456789-TEST_PROV",
"cmr:concept_id": "G000000000-TEST_PROV",
"cmr:provider": "TEST_PROV",
datetime: "2009-09-14T00:00:00.000Z",
start_datetime: "2009-09-14T00:00:00.000Z",
end_datetime: "2010-09-14T00:00:00.000Z",
Expand Down Expand Up @@ -110,7 +115,9 @@ describe("granuleToStac", () => {
type: "Feature",
id: baseGranule.title,
stac_version: "1.0.0",
stac_extensions: [],
stac_extensions: [
"https://stac-extensions.github.io/cmr/v0.0.0/schema.json"
],
geometry: {
type: "Polygon",
coordinates: [
Expand All @@ -125,6 +132,9 @@ describe("granuleToStac", () => {
},
bbox: [-180, -60, 170, 50],
properties: {
"cmr:collection_id": "C123456789-TEST_PROV",
"cmr:concept_id": "G000000000-TEST_PROV",
"cmr:provider": "TEST_PROV",
datetime: "2009-09-14T00:00:00.000Z",
start_datetime: "2009-09-14T00:00:00.000Z",
end_datetime: "2010-09-14T00:00:00.000Z",
Expand Down Expand Up @@ -197,7 +207,9 @@ describe("granuleToStac", () => {
type: "Feature",
id: baseGranule.title,
stac_version: "1.0.0",
stac_extensions: [],
stac_extensions: [
"https://stac-extensions.github.io/cmr/v0.0.0/schema.json"
],
geometry: {
type: "LineString",
coordinates: [
Expand All @@ -208,6 +220,9 @@ describe("granuleToStac", () => {
},
bbox: [-42.915595, 60.477742, 11.618598, 65.941741],
properties: {
"cmr:collection_id": "C123456789-TEST_PROV",
"cmr:concept_id": "G000000000-TEST_PROV",
"cmr:provider": "TEST_PROV",
datetime: "2009-09-14T00:00:00.000Z",
start_datetime: "2009-09-14T00:00:00.000Z",
end_datetime: "2010-09-14T00:00:00.000Z",
Expand Down
15 changes: 15 additions & 0 deletions src/domains/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ const cloudCoverExtension = (granule: Granule) => {
};
};

/**
* Return the CMR extension schema and properties for a granule.
*/
const cmrGranuleExtension = (granule: Granule) => {
return {
extension: "https://stac-extensions.github.io/cmr/v0.0.0/schema.json",
properties: {
"cmr:provider": granule.collection?.conceptId.split("-")[1],
"cmr:collection_id": granule.collection?.conceptId,
"cmr:concept_id": granule.conceptId
},
};
};

/**
* Returns the self-links for a STACItem.
*
Expand Down Expand Up @@ -166,6 +180,7 @@ export const granuleToStac = (granule: Granule): STACItem => {

const { extensions, properties: extensionProperties } = deriveExtensions(granule, [
cloudCoverExtension,
cmrGranuleExtension
]);

const properties: { [key: string]: string } = mergeMaybe(
Expand Down

0 comments on commit 4ebbd83

Please sign in to comment.