Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2024.01.xx] #10083: Persistence of COG layer's metadata info in catalog service (#10089) #10098

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion docs/developer-guide/local-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ Set `selectedService` value to one of the ID of the services object ("Demo CSW S
"filter": { // applicable only for CSW service
"staticFilter": "filter is always applied, even when search text is NOT PRESENT",
"dynamicFilter": "filter is used when search text is PRESENT and is applied in `AND` with staticFilter. The template is used with ${searchText} placeholder to append search string"
}
},
"fetchMetadata": true, // "if true, the metadata is fetched for the service, applicable only for COG service
"records": [{ // array of the COG layers of the service, applicable only for COG service
"sourceMetadata": "metadata of the COG layer",
"bbox": "bbox formulated for the COG layer",
"url": "the url pointing to the COG layer data"
}]
}
```

Expand All @@ -235,6 +241,34 @@ CSW service
}
```

COG service
<br> `fetchMetadata` - By default, the metadata is fetched on saving the COG service for each layer (url) configured<br>
<br> `records` - Records of the COG layer <br>
<br>Example:<br>

```javascript
{
"fetchMetadata": true,
"records": [{
"url": "https://example.tif",
"sourceMetadata": {
"crs": "EPSG:32632",
"extent": [463560, 5758030, 469410, 5767210],
"height": 900,
"width": 500,
"tileWidth": 256,
"tileHeight": 256,
"origin": [463560, 5767210, 0],
"resolution": [10, -10, 0]
},
"bbox": {
"crs": "EPSG:32632"
"bounds": {minx: 463560, miny: 5758030, maxx: 469410, maxy: 5767210}
}
}]
}
```

<br>Be careful to use unique IDs
<br>Future implementations will try to detect the type from the url.
<br>newService is used internally as the starting object for an empty service.
Expand Down
10 changes: 5 additions & 5 deletions web/client/api/catalog/COG.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { fromUrl as fromGeotiffUrl } from 'geotiff';
import { isValidURL } from '../../utils/URLUtils';
import ConfigUtils from '../../utils/ConfigUtils';
import { isProjectionAvailable } from '../../utils/ProjectionUtils';
import { COG_LAYER_TYPE } from '../../utils/CatalogUtils';

export const COG_LAYER_TYPE = 'cog';
const searchAndPaginate = (layers, startPosition, maxRecords, text) => {
const filteredLayers = layers
.filter(({ title = "" } = {}) => !text
Expand Down Expand Up @@ -85,11 +85,11 @@ export const getRecords = (_url, startPosition, maxRecords, text, info = {}) =>
layers = service.records?.map((record) => {
const url = record.url;
let layer = {
...service,
...record,
title: record.title,
type: COG_LAYER_TYPE,
sources: [{url}],
options: service.options || {}
type: record.type ?? COG_LAYER_TYPE,
sources: record.sources ?? [{url}],
options: record.options ?? (service.options || {})
};
const controller = get(info, 'options.controller');
const isSave = get(info, 'options.save', false);
Expand Down
3 changes: 2 additions & 1 deletion web/client/api/catalog/__tests__/COG-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import { getLayerFromRecord, getCatalogRecords, validate, COG_LAYER_TYPE, getProjectionFromGeoKeys} from '../COG';
import { COG_LAYER_TYPE } from '../../../utils/CatalogUtils';
import { getLayerFromRecord, getCatalogRecords, validate, getProjectionFromGeoKeys} from '../COG';
import expect from 'expect';


Expand Down
5 changes: 3 additions & 2 deletions web/client/epics/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ import { getSelectedLayer, selectedNodesSelector } from '../selectors/layers';

import {
buildSRSMap,
extractOGCServicesReferences
extractOGCServicesReferences,
updateServiceData
} from '../utils/CatalogUtils';
import { getCapabilities, describeLayers, flatLayers } from '../api/WMS';
import CoordinatesUtils from '../utils/CoordinatesUtils';
Expand Down Expand Up @@ -130,7 +131,7 @@ export default (API) => ({
// The records are saved to catalog state on successful saving of the service.
// The flag is used to show/hide records on load in Catalog
setNewServiceStatus(true),
addCatalogService(options.service),
addCatalogService(updateServiceData(options, result)),
success({
title: "notification.success",
message: "catalog.notification.addCatalogService",
Expand Down
19 changes: 18 additions & 1 deletion web/client/utils/CatalogUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*/

import assign from 'object-assign';
import { head, isArray } from 'lodash';
import { head, isArray, get } from 'lodash';
import CoordinatesUtils from './CoordinatesUtils';
export const COG_LAYER_TYPE = 'cog';

export const buildSRSMap = (srs) => {
return srs.filter(s => CoordinatesUtils.isSRSAllowed(s)).reduce((previous, current) => {
Expand Down Expand Up @@ -92,3 +93,19 @@ export const toURLArray = (url) => {
}
return url;
};

export const updateServiceData = (options, result) => {
const isCOGService = get(options, 'service.type') === COG_LAYER_TYPE;

if (isCOGService) {
const records = get(options, 'service.records', []);
return {
...options.service,
records: records.map(record => ({
...record,
...result?.records?.find(_record => _record.url === record.url)
}))
};
}
return options.service;
};
9 changes: 9 additions & 0 deletions web/client/utils/__tests__/CatalogUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ describe('Test the CatalogUtils', () => {
expect(mergedURL3).toBe("https://a.example.com/wms,https://b.example.com/wms,https://c.example.com/wms");
expect(mergedURL4).toBe("https://a.example.com/wms,https://b.example.com/wms");
});
it("updateServiceData", () => {
let records = [{"url": "https://example.tif", sourceMetadata: {crs: "EPSG:3003"}}];
let options = {service: {type: CatalogUtils.COG_LAYER_TYPE, records: [{url: "https://example.tif"}]}};
expect(CatalogUtils.updateServiceData(options, {records})).toEqual({...options.service, records});

records = [{"url": "https://example.tif", sourceMetadata: {crs: "EPSG:3003"}}];
options = {service: {type: "wms", "autoload": true}};
expect(CatalogUtils.updateServiceData(options, {records})).toEqual(options.service);
});
});
Loading