Skip to content

Commit

Permalink
Fix catalog loader
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed May 10, 2024
1 parent d81b873 commit 376fc40
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/models/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ export default class DataCatalog {
const files = await fse.readdir(this.dataFolder, { withFileTypes: true });
const promises = files.map(async (file) => {
const name = path.basename(file.name);
if (file.isFile() && name.endsWith('.json') && name !== 'catalog.json') {
if (file.isFile() && name.endsWith('.json')) {
try {
const collection = this.fixData(await fse.readJson(this.dataFolder + name));
const obj = await fse.readJson(this.dataFolder + name);
if (obj.type !== 'Collection') {
return;
}
const collection = this.fixData(obj);
if (this.supportedGeeTypes.includes(collection['gee:type'])) {
this.collections[collection.id] = collection;
}
Expand Down Expand Up @@ -180,21 +184,26 @@ export default class DataCatalog {

c.stac_extensions = [STAC_DATACUBE_EXTENSION];

// spatial dimensions for all data types
const x2 = c.extent.spatial.bbox[0].length > 4 ? 3 : 2;
const y2 = c.extent.spatial.bbox[0].length > 4 ? 4 : 3;
c['cube:dimensions'] = {
x: {
type: "spatial",
axis: "x",
extent: [c.extent.spatial.bbox[0][0], c.extent.spatial.bbox[0][x2]]
},
y: {
type: "spatial",
axis: "y",
extent: [c.extent.spatial.bbox[0][1], c.extent.spatial.bbox[0][y2]]
},
};
if (!c.extent || !c.extent.spatial || !c.extent.spatial.bbox) {
console.log("Invalid spatial extent for " + c.id);
}
else {
// spatial dimensions for all data types
const x2 = c.extent.spatial.bbox[0].length > 4 ? 3 : 2;
const y2 = c.extent.spatial.bbox[0].length > 4 ? 4 : 3;
c['cube:dimensions'] = {
x: {
type: "spatial",
axis: "x",
extent: [c.extent.spatial.bbox[0][0], c.extent.spatial.bbox[0][x2]]
},
y: {
type: "spatial",
axis: "y",
extent: [c.extent.spatial.bbox[0][1], c.extent.spatial.bbox[0][y2]]
},
};
}

// temporal dimension only for image collections
if (c['gee:type'] === 'image_collection') {
Expand Down

0 comments on commit 376fc40

Please sign in to comment.