diff --git a/src/Stars.Data.Tests/Resources/BKA/L1B/MetadataExtractorsTests_4077631-0220-MUL-B-1-1-1100761-150924T044238-ID.json b/src/Stars.Data.Tests/Resources/BKA/L1B/MetadataExtractorsTests_4077631-0220-MUL-B-1-1-1100761-150924T044238-ID.json new file mode 100644 index 00000000..753156c0 --- /dev/null +++ b/src/Stars.Data.Tests/Resources/BKA/L1B/MetadataExtractorsTests_4077631-0220-MUL-B-1-1-1100761-150924T044238-ID.json @@ -0,0 +1,157 @@ +{ + "stac_version": "1.0.0", + "stac_extensions": [ + "https://stac-extensions.github.io/eo/v1.0.0/schema.json", + "https://stac-extensions.github.io/processing/v1.0.0/schema.json", + "https://stac-extensions.github.io/projection/v1.0.0/schema.json", + "https://stac-extensions.github.io/raster/v1.0.0/schema.json", + "https://stac-extensions.github.io/sat/v1.0.0/schema.json", + "https://stac-extensions.github.io/view/v1.0.0/schema.json" + ], + "type": "Feature", + "id": "4077631-0220-MUL-B-1-1-1100761-150924T044238-ID", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 106.57921007, + -6.53413954 + ], + [ + 106.75128472, + -6.5002322 + ], + [ + 106.63078125, + -5.88774143 + ], + [ + 106.45888021, + -5.92156087 + ], + [ + 106.57921007, + -6.53413954 + ] + ] + ] + }, + "properties": { + "datetime": "2015-09-24T04:43:01.0000000Z", + "created": "2021-06-11T15:35:42.0000000Z", + "platform": "bka/kanopus-v", + "constellation": "bka", + "mission": "bka", + "instruments": [ + "mss" + ], + "sensor_type": "optical", + "spectral_mode": "MUL", + "sat:platform_international_designator": "2012-039B", + "proj:epsg": 32748, + "proj:shape": [ + 6792, + 3057 + ], + "view:azimuth": 84.08, + "processing:level": "L1B", + "title": "BKA/KANOPUS-V MSS L1B 2015-09-24 04:43:01", + "providers": [ + { + "name": "NAS", + "description": "BKA (formerly known as BelKa 2) is a Belarusian remote sensing satellite developed under an agreement between the National Academy of Sciences of Belarus (NAS) and the Federal Space Agency of the Russian Federation. The BKA satellite is almost an exact copy of the Russian Kanopus-Vulkan N1 Environmental Satellite (Kanopus-V 1).", + "roles": [ + "producer", + "processor", + "licensor" + ], + "url": "https://gis.by/en/tech/bka/" + } + ], + "licence": "proprietary", + "gsd": 10.52 + }, + "bbox": [ + 106.45888021, + -6.53413954, + 106.75128472, + -5.88774143 + ], + "assets": { + "L1B_MUL": { + "type": "image/tiff; application=geotiff", + "roles": [ + "data", + "dn" + ], + "href": "data/4077631-0220-MUL-B-1-1-1100761-150924T044238-ID/4077631-0220-MUL-B-1-1-1100761-150924T044238-ID.tif", + "title": "L1B MUL", + "filename": "4077631-0220-MUL-B-1-1-1100761-150924T044238-ID.tif", + "file:size": 0, + "eo:bands": [ + { + "name": "MS1", + "common_name": "blue", + "center_wavelength": 0.492, + "full_width_half_max": 0.04 + }, + { + "name": "MS2", + "common_name": "green", + "center_wavelength": 0.558, + "full_width_half_max": 0.07 + }, + { + "name": "MS3", + "common_name": "red", + "center_wavelength": 0.675, + "full_width_half_max": 0.09 + }, + { + "name": "MS4", + "common_name": "nir", + "center_wavelength": 0.782, + "full_width_half_max": 0.1 + } + ], + "raster:bands": [ + { + "data_type": "int8", + "offset": 0.0 + }, + { + "data_type": "int8", + "offset": 0.0 + }, + { + "data_type": "int8", + "offset": 0.0 + }, + { + "data_type": "int8", + "offset": 0.0 + } + ] + }, + "metadata": { + "type": "application/xml", + "roles": [ + "metadata" + ], + "href": "data/4077631-0220-MUL-B-1-1-1100761-150924T044238-ID/4077631-0220-MUL-B-1-1-1100761-150924T044238-ID_pasp-en.xml", + "filename": "4077631-0220-MUL-B-1-1-1100761-150924T044238-ID_pasp-en.xml", + "file:size": 4651 + }, + "overview": { + "type": "image/jpeg", + "roles": [ + "overview" + ], + "href": "data/4077631-0220-MUL-B-1-1-1100761-150924T044238-ID/4077631-0220-MUL-B-1-1-1100761-150924T044238-ID_preview.jpg", + "filename": "4077631-0220-MUL-B-1-1-1100761-150924T044238-ID_preview.jpg", + "file:size": 135101 + } + }, + "links": [] +} \ No newline at end of file diff --git a/src/Stars.Data.Tests/Resources/BKA/L1B/MetadataExtractorsTests_4077631-0220-PAN-B-1-1-1100761-150924T044238-ID.json b/src/Stars.Data.Tests/Resources/BKA/L1B/MetadataExtractorsTests_4077631-0220-PAN-B-1-1-1100761-150924T044238-ID.json new file mode 100644 index 00000000..768a1a4c --- /dev/null +++ b/src/Stars.Data.Tests/Resources/BKA/L1B/MetadataExtractorsTests_4077631-0220-PAN-B-1-1-1100761-150924T044238-ID.json @@ -0,0 +1,111 @@ +{ + "stac_version": "1.0.0", + "stac_extensions": [ + "https://stac-extensions.github.io/processing/v1.0.0/schema.json", + "https://stac-extensions.github.io/projection/v1.0.0/schema.json", + "https://stac-extensions.github.io/sat/v1.0.0/schema.json", + "https://stac-extensions.github.io/view/v1.0.0/schema.json" + ], + "type": "Feature", + "id": "4077631-0220-PAN-B-1-1-1100761-150924T044238-ID", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 106.56015625, + -6.53788954 + ], + [ + 106.76961806, + -6.4966173 + ], + [ + 106.64908854, + -5.88413628 + ], + [ + 106.43984375, + -5.92530165 + ], + [ + 106.56015625, + -6.53788954 + ] + ] + ] + }, + "properties": { + "datetime": "2015-09-24T04:43:02.0000000Z", + "created": "2021-06-11T15:35:50.0000000Z", + "platform": "bka/kanopus-v", + "constellation": "bka", + "mission": "bka", + "instruments": [ + "mss" + ], + "sensor_type": "optical", + "spectral_mode": "PAN", + "sat:platform_international_designator": "2012-039B", + "proj:epsg": 32748, + "proj:shape": [ + 34087, + 17123 + ], + "view:azimuth": 84.08, + "processing:level": "L1B", + "title": "BKA/KANOPUS-V MSS L1B 2015-09-24 04:43:02", + "providers": [ + { + "name": "NAS", + "description": "BKA (formerly known as BelKa 2) is a Belarusian remote sensing satellite developed under an agreement between the National Academy of Sciences of Belarus (NAS) and the Federal Space Agency of the Russian Federation. The BKA satellite is almost an exact copy of the Russian Kanopus-Vulkan N1 Environmental Satellite (Kanopus-V 1).", + "roles": [ + "producer", + "processor", + "licensor" + ], + "url": "https://gis.by/en/tech/bka/" + } + ], + "licence": "proprietary", + "gsd": 2.12 + }, + "bbox": [ + 106.43984375, + -6.53788954, + 106.76961806, + -5.88413628 + ], + "assets": { + "L1B_PAN": { + "type": "image/tiff; application=geotiff", + "roles": [ + "data", + "dn" + ], + "href": "data/4077631-0220-PAN-B-1-1-1100761-150924T044238-ID/4077631-0220-PAN-B-1-1-1100761-150924T044238-ID.tif", + "title": "L1B PAN", + "filename": "4077631-0220-PAN-B-1-1-1100761-150924T044238-ID.tif", + "file:size": 0 + }, + "metadata": { + "type": "application/xml", + "roles": [ + "metadata" + ], + "href": "data/4077631-0220-PAN-B-1-1-1100761-150924T044238-ID/4077631-0220-PAN-B-1-1-1100761-150924T044238-ID_pasp-en.xml", + "filename": "4077631-0220-PAN-B-1-1-1100761-150924T044238-ID_pasp-en.xml", + "file:size": 4160 + }, + "overview": { + "type": "image/jpeg", + "roles": [ + "overview" + ], + "href": "data/4077631-0220-PAN-B-1-1-1100761-150924T044238-ID/4077631-0220-PAN-B-1-1-1100761-150924T044238-ID_preview.jpg", + "filename": "4077631-0220-PAN-B-1-1-1100761-150924T044238-ID_preview.jpg", + "file:size": 139746 + } + }, + "links": [] +} \ No newline at end of file diff --git a/src/Stars.Data.Tests/Resources/BKA/L1C/MetadataExtractorsTests_4077631-0220-MUL-C-1-1-1100761-150924T044238-ID.json b/src/Stars.Data.Tests/Resources/BKA/L1C/MetadataExtractorsTests_4077631-0220-MUL-C-1-1-1100761-150924T044238-ID.json new file mode 100644 index 00000000..38c2727b --- /dev/null +++ b/src/Stars.Data.Tests/Resources/BKA/L1C/MetadataExtractorsTests_4077631-0220-MUL-C-1-1-1100761-150924T044238-ID.json @@ -0,0 +1,157 @@ +{ + "stac_version": "1.0.0", + "stac_extensions": [ + "https://stac-extensions.github.io/eo/v1.0.0/schema.json", + "https://stac-extensions.github.io/processing/v1.0.0/schema.json", + "https://stac-extensions.github.io/projection/v1.0.0/schema.json", + "https://stac-extensions.github.io/raster/v1.0.0/schema.json", + "https://stac-extensions.github.io/sat/v1.0.0/schema.json", + "https://stac-extensions.github.io/view/v1.0.0/schema.json" + ], + "type": "Feature", + "id": "4077631-0220-MUL-C-1-1-1100761-150924T044238-ID", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 106.57943576, + -6.53408095 + ], + [ + 106.75134549, + -6.50028809 + ], + [ + 106.63111111, + -5.88778429 + ], + [ + 106.459375, + -5.92148926 + ], + [ + 106.57943576, + -6.53408095 + ] + ] + ] + }, + "properties": { + "datetime": "2015-09-24T04:43:01.0000000Z", + "created": "2021-06-11T16:38:46.0000000Z", + "platform": "bka/kanopus-v", + "constellation": "bka", + "mission": "bka", + "instruments": [ + "mss" + ], + "sensor_type": "optical", + "spectral_mode": "MUL", + "sat:platform_international_designator": "2012-039B", + "proj:epsg": 32748, + "proj:shape": [ + 6791, + 3052 + ], + "view:azimuth": 84.08, + "processing:level": "L1C", + "title": "BKA/KANOPUS-V MSS L1C 2015-09-24 04:43:01", + "providers": [ + { + "name": "NAS", + "description": "BKA (formerly known as BelKa 2) is a Belarusian remote sensing satellite developed under an agreement between the National Academy of Sciences of Belarus (NAS) and the Federal Space Agency of the Russian Federation. The BKA satellite is almost an exact copy of the Russian Kanopus-Vulkan N1 Environmental Satellite (Kanopus-V 1).", + "roles": [ + "producer", + "processor", + "licensor" + ], + "url": "https://gis.by/en/tech/bka/" + } + ], + "licence": "proprietary", + "gsd": 10.52 + }, + "bbox": [ + 106.459375, + -6.53408095, + 106.75134549, + -5.88778429 + ], + "assets": { + "L1C_MUL": { + "type": "image/tiff; application=geotiff", + "roles": [ + "data", + "dn" + ], + "href": "data/4077631-0220-MUL-C-1-1-1100761-150924T044238-ID/4077631-0220-MUL-C-1-1-1100761-150924T044238-ID.tif", + "title": "L1C MUL", + "filename": "4077631-0220-MUL-C-1-1-1100761-150924T044238-ID.tif", + "file:size": 0, + "eo:bands": [ + { + "name": "MS1", + "common_name": "blue", + "center_wavelength": 0.492, + "full_width_half_max": 0.04 + }, + { + "name": "MS2", + "common_name": "green", + "center_wavelength": 0.558, + "full_width_half_max": 0.07 + }, + { + "name": "MS3", + "common_name": "red", + "center_wavelength": 0.675, + "full_width_half_max": 0.09 + }, + { + "name": "MS4", + "common_name": "nir", + "center_wavelength": 0.782, + "full_width_half_max": 0.1 + } + ], + "raster:bands": [ + { + "data_type": "int8", + "offset": 0.0 + }, + { + "data_type": "int8", + "offset": 0.0 + }, + { + "data_type": "int8", + "offset": 0.0 + }, + { + "data_type": "int8", + "offset": 0.0 + } + ] + }, + "metadata": { + "type": "application/xml", + "roles": [ + "metadata" + ], + "href": "data/4077631-0220-MUL-C-1-1-1100761-150924T044238-ID/4077631-0220-MUL-C-1-1-1100761-150924T044238-ID_pasp-en.xml", + "filename": "4077631-0220-MUL-C-1-1-1100761-150924T044238-ID_pasp-en.xml", + "file:size": 4652 + }, + "overview": { + "type": "image/jpeg", + "roles": [ + "overview" + ], + "href": "data/4077631-0220-MUL-C-1-1-1100761-150924T044238-ID/4077631-0220-MUL-C-1-1-1100761-150924T044238-ID_preview.jpg", + "filename": "4077631-0220-MUL-C-1-1-1100761-150924T044238-ID_preview.jpg", + "file:size": 138091 + } + }, + "links": [] +} \ No newline at end of file diff --git a/src/Stars.Data.Tests/Resources/BKA/L1C/MetadataExtractorsTests_4077631-0220-PAN-C-1-1-1100761-150924T044238-ID.json b/src/Stars.Data.Tests/Resources/BKA/L1C/MetadataExtractorsTests_4077631-0220-PAN-C-1-1-1100761-150924T044238-ID.json new file mode 100644 index 00000000..535ee5a8 --- /dev/null +++ b/src/Stars.Data.Tests/Resources/BKA/L1C/MetadataExtractorsTests_4077631-0220-PAN-C-1-1-1100761-150924T044238-ID.json @@ -0,0 +1,111 @@ +{ + "stac_version": "1.0.0", + "stac_extensions": [ + "https://stac-extensions.github.io/processing/v1.0.0/schema.json", + "https://stac-extensions.github.io/projection/v1.0.0/schema.json", + "https://stac-extensions.github.io/sat/v1.0.0/schema.json", + "https://stac-extensions.github.io/view/v1.0.0/schema.json" + ], + "type": "Feature", + "id": "4077631-0220-PAN-C-1-1-1100761-150924T044238-ID", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 106.56038194, + -6.53782335 + ], + [ + 106.76985243, + -6.49664605 + ], + [ + 106.64960069, + -5.88415202 + ], + [ + 106.44033854, + -5.92522244 + ], + [ + 106.56038194, + -6.53782335 + ] + ] + ] + }, + "properties": { + "datetime": "2015-09-24T04:43:02.0000000Z", + "created": "2021-06-11T16:38:54.0000000Z", + "platform": "bka/kanopus-v", + "constellation": "bka", + "mission": "bka", + "instruments": [ + "mss" + ], + "sensor_type": "optical", + "spectral_mode": "PAN", + "sat:platform_international_designator": "2012-039B", + "proj:epsg": 32748, + "proj:shape": [ + 34082, + 17110 + ], + "view:azimuth": 84.08, + "processing:level": "L1C", + "title": "BKA/KANOPUS-V MSS L1C 2015-09-24 04:43:02", + "providers": [ + { + "name": "NAS", + "description": "BKA (formerly known as BelKa 2) is a Belarusian remote sensing satellite developed under an agreement between the National Academy of Sciences of Belarus (NAS) and the Federal Space Agency of the Russian Federation. The BKA satellite is almost an exact copy of the Russian Kanopus-Vulkan N1 Environmental Satellite (Kanopus-V 1).", + "roles": [ + "producer", + "processor", + "licensor" + ], + "url": "https://gis.by/en/tech/bka/" + } + ], + "licence": "proprietary", + "gsd": 2.12 + }, + "bbox": [ + 106.44033854, + -6.53782335, + 106.76985243, + -5.88415202 + ], + "assets": { + "L1C_PAN": { + "type": "image/tiff; application=geotiff", + "roles": [ + "data", + "dn" + ], + "href": "data/4077631-0220-PAN-C-1-1-1100761-150924T044238-ID/4077631-0220-PAN-C-1-1-1100761-150924T044238-ID.tif", + "title": "L1C PAN", + "filename": "4077631-0220-PAN-C-1-1-1100761-150924T044238-ID.tif", + "file:size": 0 + }, + "metadata": { + "type": "application/xml", + "roles": [ + "metadata" + ], + "href": "data/4077631-0220-PAN-C-1-1-1100761-150924T044238-ID/4077631-0220-PAN-C-1-1-1100761-150924T044238-ID_pasp-en.xml", + "filename": "4077631-0220-PAN-C-1-1-1100761-150924T044238-ID_pasp-en.xml", + "file:size": 4161 + }, + "overview": { + "type": "image/jpeg", + "roles": [ + "overview" + ], + "href": "data/4077631-0220-PAN-C-1-1-1100761-150924T044238-ID/4077631-0220-PAN-C-1-1-1100761-150924T044238-ID_preview.jpg", + "filename": "4077631-0220-PAN-C-1-1-1100761-150924T044238-ID_preview.jpg", + "file:size": 142295 + } + }, + "links": [] +} \ No newline at end of file diff --git a/src/Stars.Data.Tests/testsettings.json b/src/Stars.Data.Tests/testsettings.json index b8e946ee..26b920af 100644 --- a/src/Stars.Data.Tests/testsettings.json +++ b/src/Stars.Data.Tests/testsettings.json @@ -65,6 +65,9 @@ "KANOPUS-V": [ "ROSCOSMOS/KANOPUS-V" ], + "BKA" : [ + "BKA" + ], "ISRO": [ "ISRO" ], diff --git a/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs new file mode 100644 index 00000000..3ad7fed7 --- /dev/null +++ b/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs @@ -0,0 +1,370 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Net.Mime; +using System.Threading.Tasks; +using GeoJSON.Net.Geometry; +using Microsoft.Extensions.Logging; +using Stac; +using Stac.Extensions.Eo; +using Stac.Extensions.Processing; +using Stac.Extensions.Projection; +using Terradue.Stars.Interface; +using Terradue.Stars.Interface.Supplier.Destination; +using Terradue.Stars.Services.Model.Stac; +using Terradue.Stars.Geometry.GeoJson; +using System.Xml; +using System.Xml.Serialization; +using Stac.Extensions.Sat; +using Stac.Extensions.View; +using Stac.Extensions.Raster; + + + + +namespace Terradue.Stars.Data.Model.Metadata.Bka +{ + public class BkaMetadataExtractor : MetadataExtraction + { + public override string Label => "BKA (Belarus) mission product metadata extractor"; + + public static XmlSerializer metadataSerializer = new XmlSerializer(typeof(BkaMetadata)); + + public BkaMetadataExtractor(ILogger logger, IResourceServiceProvider resourceServiceProvider) : base(logger, resourceServiceProvider) + { + } + + public override bool CanProcess(IResource route, IDestination destination) + { + IItem item = route as IItem; + if (item == null) return false; + try + { + IAsset metadataAsset = GetMetadataAsset(item); + BkaMetadata metadata = ReadMetadata(metadataAsset).GetAwaiter().GetResult(); + return metadata != null; + } + catch (Exception) + { + return false; + } + } + + protected override async Task ExtractMetadata(IItem item, string suffix) + { + IAsset metadataAsset = GetMetadataAsset(item); + BkaMetadata metadata = await ReadMetadata(metadataAsset); + + StacItem stacItem = CreateStacItem(metadata); + + AddAssets(stacItem, item, metadata); + + return StacItemNode.Create(stacItem, item.Uri); ; + } + + + internal virtual StacItem CreateStacItem(BkaMetadata metadata) + { + string identifier = metadata.Processing.Scene01FileName.Replace(".tif", String.Empty); + StacItem stacItem = new StacItem(identifier, GetGeometry(metadata), GetCommonMetadata(metadata)); + AddSatStacExtension(metadata, stacItem); + AddProjStacExtension(metadata, stacItem); + AddProjViewExtension(metadata, stacItem); + AddProcessingStacExtension(metadata, stacItem); + AddEoStacExtension(metadata, stacItem); + FillBasicsProperties(metadata, stacItem.Properties); + AddOtherProperties(metadata, stacItem); + + return stacItem; + } + + private void AddEoStacExtension(BkaMetadata metadata, StacItem stacItem) + { + EoStacExtension eo = stacItem.EoExtension(); + } + + + private void AddSatStacExtension(BkaMetadata metadata, StacItem stacItem) + { + SatStacExtension sat = stacItem.SatExtension(); + sat.PlatformInternationalDesignator = "2012-039B"; + } + + private void AddProjStacExtension(BkaMetadata metadata, StacItem stacItem) + { + ProjectionStacExtension proj = stacItem.ProjectionExtension(); + proj.Epsg = metadata.GeoReference?.EpsgCode; + if (metadata.ImageInfo != null && metadata.ImageInfo.Height != null && metadata.ImageInfo.Width != null) + { + proj.Shape = new int[2] { metadata.ImageInfo.Height.Value, metadata.ImageInfo.Width.Value }; + } + } + + private void AddProjViewExtension(BkaMetadata metadata, StacItem stacItem) + { + ViewStacExtension view = stacItem.ViewExtension(); + if (metadata.SatelliteData != null && metadata.SatelliteData.SceneAcquisition != null) + { + BkaSceneAcquisition sceneAcquisition = metadata.SatelliteData.SceneAcquisition; + if (sceneAcquisition.ViewingAngle != null) view.Azimuth = sceneAcquisition.ViewingAngle.Value; + if (sceneAcquisition.SunAzimuth != null) view.Azimuth = sceneAcquisition.SunAzimuth.Value; + if (sceneAcquisition.SunElevation != null) view.Azimuth = sceneAcquisition.SunElevation.Value; + } + } + + private void AddProcessingStacExtension(BkaMetadata metadata, StacItem stacItem) + { + var proc = stacItem.ProcessingExtension(); + if (metadata.Processing != null && metadata.Processing.Level != null) + { + proc.Level = GetProcessingLevel(metadata); + } + } + + private string GetProcessingLevel(BkaMetadata metadata) + { + return String.Format("L1{0}", metadata.Processing.Level); + } + + private string GetInstrument(BkaMetadata metadata) + { + return "MSS"; + } + + private IDictionary GetCommonMetadata(BkaMetadata metadata) + { + Dictionary properties = new Dictionary(); + + FillDateTimeProperties(metadata, properties); + FillPlatformDefinition(metadata, properties); + + + return properties; + } + + private void FillBasicsProperties(BkaMetadata metadata, IDictionary properties) + { + CultureInfo culture = new CultureInfo("fr-FR"); + // title + properties.Remove("title"); + properties.Add("title", string.Format("{0} {1} {2} {3}", + //StylePlatform(properties.GetProperty("platform")), + properties.GetProperty("platform").ToUpper(), + GetInstrument(metadata), + GetProcessingLevel(metadata), + properties.GetProperty("datetime").ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss", culture)) + ); + } + + private void AddOtherProperties(BkaMetadata metadata, StacItem item) + { + IDictionary properties = item.Properties; + if (IncludeProviderProperty) + { + AddSingleProvider( + properties, + "NAS", + "BKA (formerly known as BelKa 2) is a Belarusian remote sensing satellite developed under an agreement between the National Academy of Sciences of Belarus (NAS) and the Federal Space Agency of the Russian Federation. The BKA satellite is almost an exact copy of the Russian Kanopus-Vulkan N1 Environmental Satellite (Kanopus-V 1).", + new StacProviderRole[] { StacProviderRole.producer, StacProviderRole.processor, StacProviderRole.licensor }, + new Uri("https://gis.by/en/tech/bka/") + ); + } + properties["licence"] = "proprietary"; + if (metadata.GeoReference.SceneGeoposition.GroundResolution != null) + { + item.Gsd = metadata.GeoReference.SceneGeoposition.GroundResolution.PixelSizeNorthing; + } + } + + + private void FillDateTimeProperties(BkaMetadata metadata, Dictionary properties) + { + var format = "yyyy-MM-ddTHH:mm:ss"; + var format2 = "dd.MM.yyyy HH:mm:ss"; + + if (DateTime.TryParseExact(metadata.SatelliteData.SceneAcquisition.AcquisitionTime, format, null, DateTimeStyles.AssumeUniversal, out DateTime dt)) + { + properties["datetime"] = dt.ToUniversalTime().ToString("O"); + } + if (DateTime.TryParseExact(metadata.Production?.CreationDate, format, null, DateTimeStyles.AssumeUniversal, out dt)) + { + properties["created"] = dt.ToUniversalTime().ToString("O"); + } + else if (DateTime.TryParseExact(metadata.Production?.CreationDate, format2, null, DateTimeStyles.AssumeUniversal, out dt)) + { + properties["created"] = dt.ToUniversalTime().ToString("O"); + } + } + + private void FillPlatformDefinition(BkaMetadata metadata, Dictionary properties) + { + string platform = "bka"; + if (metadata.Processing?.Satellite != null) platform = metadata.Processing.Satellite.ToLower(); + string mission = "bka"; + if (metadata.Processing?.Mission != null) platform = metadata.Processing.Mission.ToLower(); + properties["platform"] = platform; + properties["constellation"] = mission; + properties["mission"] = mission; + properties["instruments"] = new string[] { GetInstrument(metadata).ToLower() }; + properties["sensor_type"] = "optical"; + if (metadata.Processing?.Instrument != null) + properties["spectral_mode"] = metadata.Processing?.Instrument; + } + + + private GeoJSON.Net.Geometry.IGeometryObject GetGeometry(BkaMetadata metadata) + { + BkaGeodeticCoordinates coordinates = metadata.GeoReference.SceneGeoposition.GeodeticCoordinates; + List positions = new List + { + new GeoJSON.Net.Geometry.Position(coordinates.Corner1SWLat, coordinates.Corner1SWLon), + new GeoJSON.Net.Geometry.Position(coordinates.Corner4SELat, coordinates.Corner4SELon), + new GeoJSON.Net.Geometry.Position(coordinates.Corner3NELat, coordinates.Corner3NELon), + new GeoJSON.Net.Geometry.Position(coordinates.Corner2NWLat, coordinates.Corner2NWLon), + new GeoJSON.Net.Geometry.Position(coordinates.Corner1SWLat, coordinates.Corner1SWLon) + }; + GeoJSON.Net.Geometry.LineString lineString = new GeoJSON.Net.Geometry.LineString(positions.ToArray()); + return new GeoJSON.Net.Geometry.Polygon(new GeoJSON.Net.Geometry.LineString[] { lineString }).NormalizePolygon(); + } + + + protected void AddAssets(StacItem stacItem, IItem item, BkaMetadata metadata) + { + IAsset imageAsset = FindFirstAssetFromFileNameRegex(item, @".*\.tif"); + if (imageAsset != null) + { + StacAsset stacAsset = StacAsset.CreateDataAsset(stacItem, imageAsset.Uri, new ContentType("image/tiff; application=geotiff")); + stacAsset.Roles.Add("dn"); + + string key = String.Format("{0}_{1}", + GetProcessingLevel(metadata), + metadata.Processing?.Instrument + ); + stacAsset.Properties["title"] = key.Replace("_", " "); + stacAsset.Properties.AddRange(imageAsset.Properties); + + BkaSpectral spectral = metadata.Radiometry.Spectral; + if (spectral.BandMS1 != null) AddBandAsset(spectral.BandMS1, stacAsset); + if (spectral.BandMS2 != null) AddBandAsset(spectral.BandMS2, stacAsset); + if (spectral.BandMS3 != null) AddBandAsset(spectral.BandMS3, stacAsset); + if (spectral.BandMS4 != null) AddBandAsset(spectral.BandMS4, stacAsset); + + stacItem.Assets.Add(key, stacAsset); + } + + IAsset metadataAsset = GetMetadataAsset(item); + if (metadataAsset != null) + { + StacAsset stacAsset = StacAsset.CreateMetadataAsset(stacItem, metadataAsset.Uri, new ContentType(MimeTypes.GetMimeType(metadataAsset.Uri.ToString()))); + stacItem.Assets.Add("metadata", stacAsset); + stacAsset.Properties.AddRange(metadataAsset.Properties); + } + + IAsset overviewAsset = FindFirstAssetFromFileNameRegex(item, @".*_preview\.jpg"); + if (overviewAsset != null) + { + StacAsset stacAsset = StacAsset.CreateOverviewAsset(stacItem, overviewAsset.Uri, new ContentType(MimeTypes.GetMimeType(overviewAsset.Uri.ToString()))); + stacAsset.Properties.AddRange(overviewAsset.Properties); + stacItem.Assets.Add("overview", stacAsset); + } + } + + + private void AddBandAsset(BkaBandInfo bandInfo, StacAsset stacAsset = null) + { + double? waveLength; + double? fullWidthHalfMax; + double? scale = null; + + EoBandCommonName commonName; + + switch (bandInfo.BandCode) + { + case "MS1": + waveLength = 0.492; + fullWidthHalfMax = 0.04; + commonName = EoBandCommonName.blue; + break; + case "MS2": + waveLength = 0.558; + fullWidthHalfMax = 0.07; + commonName = EoBandCommonName.green; + break; + case "MS3": + waveLength = 0.675; + fullWidthHalfMax = 0.09; + commonName = EoBandCommonName.red; + break; + case "MS4": + waveLength = 0.782; + fullWidthHalfMax = 0.1; + commonName = EoBandCommonName.nir; + break; + default: + return; + } + + EoBandObject eoBandObject = new EoBandObject(bandInfo.BandCode, commonName) + { + CenterWavelength = waveLength, + FullWidthHalfMax = fullWidthHalfMax, + }; + + RasterBand rasterBand = new RasterBand() + { + DataType = Stac.Common.DataType.int8, + Scale = scale, + Offset = 0 + }; + + EoStacExtension eo = stacAsset.EoExtension(); + if (eo.Bands == null) + { + eo.Bands = new EoBandObject[] { eoBandObject }; + } + else + { + List bands = new List(eo.Bands) { eoBandObject }; + eo.Bands = bands.ToArray(); + } + + if (rasterBand != null) + { + RasterStacExtension raster = stacAsset.RasterExtension(); + if (raster.Bands == null) + { + raster.Bands = new RasterBand[] { rasterBand }; + } + else + { + List bands = new List(raster.Bands) { rasterBand }; + raster.Bands = bands.ToArray(); + } + } + } + + + protected virtual IAsset GetMetadataAsset(IItem item) + { + IAsset metadataAsset = FindFirstAssetFromFileNameRegex(item, @"^.*_pasp-en\.xml"); + if (metadataAsset != null) return metadataAsset; + + throw new FileNotFoundException(String.Format("Unable to find the summary file asset")); + } + + public virtual async Task ReadMetadata(IAsset metadataAsset) + { + using (var stream = await resourceServiceProvider.GetAssetStreamAsync(metadataAsset, System.Threading.CancellationToken.None)) + { + XmlReaderSettings settings = new XmlReaderSettings() { DtdProcessing = DtdProcessing.Ignore }; + var reader = XmlReader.Create(stream, settings); + + logger.LogDebug("Deserializing metadata file {0}", metadataAsset.Uri); + + return (BkaMetadata)metadataSerializer.Deserialize(reader); + } + } + } +} \ No newline at end of file diff --git a/src/Stars.Data/Model/Metadata/Bka/Schema.cs b/src/Stars.Data/Model/Metadata/Bka/Schema.cs index d3779817..6565042b 100644 --- a/src/Stars.Data/Model/Metadata/Bka/Schema.cs +++ b/src/Stars.Data/Model/Metadata/Bka/Schema.cs @@ -3,7 +3,7 @@ namespace Terradue.Stars.Data.Model.Metadata.Bka { - [XmlRoot(ElementName = "Metadata")] + [XmlRoot(ElementName = "MetaData")] public class BkaMetadata { @@ -157,7 +157,7 @@ public class BkaGeoReference public int? EpsgCode { get; set; } [XmlElement(ElementName = "EPSG_tables")] - public string EPSGTables { get; set; } + public string EpsgTables { get; set; } [XmlElement(ElementName = "Elevation_Data")] public BkaElevationData ElevationData { get; set; } @@ -171,15 +171,6 @@ public class BkaGeoReference [XmlRoot(ElementName = "Image_Info")] public class BkaImageInfo { - /* - - - Bilinear Interpolation - - - */ - - [XmlElement(ElementName = "File_Format")] public string FileFormat { get; set; } @@ -222,26 +213,11 @@ public class BkaImageInfo [XmlRoot(ElementName = "Scene_Acquisition")] public class BkaSceneAcquisition { - /* - - BKA - 2015-09-24T04:43:01 - 84.08 - 6.84 - 2.31 -
- -6.21091851 - 106.60503472 -
-
- */ - - [XmlElement(ElementName = "Satellite")] - public string SceneAcquisition { get; set; } + public string Satellite { get; set; } [XmlElement(ElementName = "Acquisition_Time_GMT")] - public string RoutesCount { get; set; } + public string AcquisitionTime { get; set; } [XmlElement(ElementName = "Sun_Elevation")] public double? SunElevation { get; set; } @@ -343,22 +319,22 @@ public class BkaGeodeticCoordinates public double Corner1SWLon { get; set; } [XmlElement(ElementName = "Corner2_NW_Lat")] - public double Corner1NWLat { get; set; } + public double Corner2NWLat { get; set; } [XmlElement(ElementName = "Corner2_NW_Lon")] - public double Corner1NWLon { get; set; } + public double Corner2NWLon { get; set; } [XmlElement(ElementName = "Corner3_NE_Lat")] - public double Corner1NELat { get; set; } + public double Corner3NELat { get; set; } [XmlElement(ElementName = "Corner3_NE_Lon")] - public double Corner1NELon { get; set; } + public double Corner3NELon { get; set; } [XmlElement(ElementName = "Corner4_SE_Lat")] - public double Corner1SELat { get; set; } + public double Corner4SELat { get; set; } [XmlElement(ElementName = "Corner4_SE_Lon")] - public double Corner1SELon { get; set; } + public double Corner4SELon { get; set; } } @@ -372,22 +348,22 @@ public class BkaMapCoordinates public double Corner1SWNorthing { get; set; } [XmlElement(ElementName = "Corner2_NW_Easting")] - public double Corner1NWEasting { get; set; } + public double Corner2NWEasting { get; set; } [XmlElement(ElementName = "Corner2_NW_Northing")] - public double Corner1NWNorthing { get; set; } + public double Corner2NWNorthing { get; set; } [XmlElement(ElementName = "Corner3_NE_Easting")] - public double Corner1NEEasting { get; set; } + public double Corner3NEEasting { get; set; } [XmlElement(ElementName = "Corner3_NE_Northing")] - public double Corner1NENorthing { get; set; } + public double Corner3NENorthing { get; set; } [XmlElement(ElementName = "Corner4_SE_Easting")] - public double Corner1SEEasting { get; set; } + public double Corner4SEEasting { get; set; } [XmlElement(ElementName = "Corner4_SE_Northing")] - public double Corner1SENorthing { get; set; } + public double Corner4SENorthing { get; set; } } diff --git a/src/Stars.Data/stars-data.json b/src/Stars.Data/stars-data.json index 4e7b0f55..fb74f7de 100644 --- a/src/Stars.Data/stars-data.json +++ b/src/Stars.Data/stars-data.json @@ -112,6 +112,9 @@ "KANOPUS-V": { "Type": "Terradue.Stars.Data.Model.Metadata.Kanopus.KanopusVMetadataExtractor" }, + "BKA": { + "Type": "Terradue.Stars.Data.Model.Metadata.Bka.BkaMetadataExtractor" + }, "ISRO": { "Type": "Terradue.Stars.Data.Model.Metadata.Isro.IsroMetadataExtractor" },