From 5c67bf774d14294b9ee8f2700be0dea5d90f43f8 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Tue, 11 Apr 2023 19:28:20 +0200 Subject: [PATCH] Draft for equi7 support #301 --- docs/geotiff.md | 2 +- src/components/maps/projManager.js | 36 ++++++++++++++++++++++++------ src/formats/geotiff.js | 10 ++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/docs/geotiff.md b/docs/geotiff.md index 625abb82c..26ce28050 100644 --- a/docs/geotiff.md +++ b/docs/geotiff.md @@ -19,7 +19,7 @@ What is required by back-ends to give users an ideal experience with GeoTiff ima 1. The no-data value either in `file:nodata` (deprecated) or in `nodata` in `raster:bands` 2. The `minimum` and `maximum` values per band in the `statistics` object in `raster:bands` 3. A band `name` either in `raster:bands` (unspecified) or `eo:bands` - 4. The projection in `proj:epsg` (recommended), `proj:wkt2` (not well suported by OpenLayers) or `proj:proj4` (deprecated by STAC) + 4. The projection in `proj:epsg` (recommended), `proj:wkt2` (not suported by OpenLayers), or `equi7:proj` (proprietary). 5. The `type` must be set to the corresponding media type (see below) 8. For synchronous execution, the `Content-Type` in the header of the response must be set to the corresponding media type (see below) diff --git a/src/components/maps/projManager.js b/src/components/maps/projManager.js index 684fc3dc6..38a47d59d 100644 --- a/src/components/maps/projManager.js +++ b/src/components/maps/projManager.js @@ -34,14 +34,36 @@ export default class ProjManager { } } - // Get projection details from STAC (todo: add collection support) - static async addFromStac(stac) { - if (Utils.isObject(stac) && Utils.isObject(stac.properties)) { - if (stac.properties['proj:epsg']) { - return await ProjManager.get(stac.properties['proj:epsg']); + static async addFromStacItem(stac) { + if (Utils.isObject(stac)) { + return await this.addFromStacObject(stac.properties, stac.id); + } + return null; + } + static async addFromStacCollection(stac) { + if (Utils.isObject(stac)) { + // Todo: Handle arrays in summaries... + // return await this.addFromStacObject(stac.summaries, stac.id); + } + return null; + } + + // Get projection details from STAC Asset + static async addFromStacAsset(asset) { + return await this.addFromStacObject(asset, asset.href); + } + + // Get projection details from STAC Asset + static async addFromStacObject(obj, id) { + if (Utils.isObject(obj)) { + if (obj['proj:epsg']) { + return await ProjManager.get(obj['proj:epsg']); + } + else if (obj['equi7:proj']) { + return ProjManager.add(id, obj['equi7:proj']); } - else if (stac.properties['proj:wkt2']) { - return ProjManager.add(stac.id, stac.properties['proj:wkt2']); + else if (obj['proj:wkt2']) { + return ProjManager.add(id, obj['proj:wkt2']); } } return null; diff --git a/src/formats/geotiff.js b/src/formats/geotiff.js index 4602252c4..a9636c89e 100644 --- a/src/formats/geotiff.js +++ b/src/formats/geotiff.js @@ -49,7 +49,15 @@ class GeoTIFF extends SupportedFormat { let stacHasExtent = this.stac && (this.stac.geometry || this.stac.extent); // Get projection from STAC - this.projection = await ProjManager.addFromStac(this.stac); + if (this.stac.type === 'Feature') { + this.projection = await ProjManager.addFromStacItem(this.stac); + } + else if (this.stac.type === 'Collection') { + this.projection = await ProjManager.addFromStacCollection(this.stac); + } + else { + this.projection = await ProjManager.addFromStacAsset(this.stac); + } // Get nodata from STAC file:nodata if (Array.isArray(this['file:nodata']) && this['file:nodata'].length > 0) {