From 9a765bb0d4672498eb2a2b071d8e5900447e8bf3 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Thu, 1 Oct 2020 11:30:03 +0200 Subject: [PATCH] fixed bugs on EO extension --- src/DotNetStac.Test/Item/EoExtensionTests.cs | 47 +++++ ...K3A_20200508102646_28267_00027320_L1G.json | 194 ++++++++++++++++++ ...2646_28267_00027320_L1G_missing_bands.json | 184 +++++++++++++++++ .../Extensions/Eo/EoStacExtension.cs | 6 +- .../Projection/ProjectionStacExtension.cs | 2 +- src/DotNetStac/Extensions/StacExtensions.cs | 4 +- .../Extensions/StacExtensionsFactory.cs | 3 + .../Extensions/View/ViewStacExtension.cs | 2 +- 8 files changed, 435 insertions(+), 7 deletions(-) create mode 100644 src/DotNetStac.Test/Item/EoExtensionTests.cs create mode 100644 src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G.json create mode 100644 src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G_missing_bands.json diff --git a/src/DotNetStac.Test/Item/EoExtensionTests.cs b/src/DotNetStac.Test/Item/EoExtensionTests.cs new file mode 100644 index 00000000..8070b18f --- /dev/null +++ b/src/DotNetStac.Test/Item/EoExtensionTests.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Stac.Extensions.Sat; +using GeoJSON.Net; +using GeoJSON.Net.Geometry; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Stac.Item; +using Xunit; +using System.IO; +using Stac.Extensions.Eo; + +namespace Stac.Test.Item +{ + public class EoExtensionTests : TestBase + { + [Fact] + public void SetAssetBands() + { + var k3CompleteJson = GetJson("Item", "K3A_20200508102646_28267_00027320_L1G"); + var k3MissingBandsJson = GetJson("Item", "K3A_20200508102646_28267_00027320_L1G_missing_bands"); + + IStacItem k3MissingBands = JsonConvert.DeserializeObject(k3MissingBandsJson); + + EoStacExtension k3MissingBandsEO = k3MissingBands.StacExtensions.GetExtension(); + + EoBandObject eoBandObject = new EoBandObject("MS1", EoBandCommonName.blue) + { + CenterWavelength = 0.485 + }; + eoBandObject.Properties.Add("scale", 27.62430939226519); + eoBandObject.Properties.Add("offset", -22.1416); + eoBandObject.Properties.Add("eai", 2001.0); + + Assert.NotNull(k3MissingBands.Assets["MS1"]); + + k3MissingBandsEO.AddBandObject(k3MissingBands.Assets["MS1"], new EoBandObject[] { eoBandObject }); + + k3MissingBandsJson = JsonConvert.SerializeObject(k3MissingBands); + + JsonAssert.AreEqual(k3CompleteJson, k3MissingBandsJson); + + } + + } +} diff --git a/src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G.json b/src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G.json new file mode 100644 index 00000000..bad8eed1 --- /dev/null +++ b/src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G.json @@ -0,0 +1,194 @@ +{ + "stac_extensions": [ + "eo", + "sat", + "proj", + "view" + ], + "stac_version": "1.0.0-beta.1", + "links": [ + { + "rel": "self", + "href": "K3A_20200508102646_28267_00027320_L1G.json" + } + ], + "assets": { + "metadata": { + "type": "text/xml", + "roles": [ + "metadata" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_Aux.xml" + }, + "MS1": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_B.tif", + "gsd": 2.2, + "eo:bands": [ + { + "name": "MS1", + "common_name": "blue", + "center_wavelength": 0.485, + "scale": 27.62430939226519, + "offset": -22.1416, + "eai": 2001.0 + } + ] + }, + "overview": { + "type": "image/jpeg", + "roles": [ + "overview" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_br.jpg" + }, + "MS2": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_G.tif", + "gsd": 2.2, + "eo:bands": [ + { + "name": "MS2", + "common_name": "green", + "center_wavelength": 0.56, + "scale": 40.16064257028113, + "offset": -14.021, + "eai": 1875.0 + } + ] + }, + "MS4": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_N.tif", + "gsd": 2.2, + "eo:bands": [ + { + "name": "MS4", + "common_name": "nir", + "center_wavelength": 0.83, + "scale": 76.92307692307692, + "offset": -10.2834, + "eai": 1027.0 + } + ] + }, + "PAN": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_P.tif", + "gsd": 0.55, + "eo:bands": [ + { + "name": "PAN", + "common_name": "pan", + "center_wavelength": 0.675 + } + ] + }, + "MS3": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_R.tif", + "gsd": 2.2, + "eo:bands": [ + { + "name": "MS3", + "common_name": "red", + "center_wavelength": 0.66, + "scale": 43.66812227074236, + "offset": -13.0457, + "eai": 1525.0 + } + ] + }, + "thumbnail": { + "type": "image/jpeg", + "roles": [ + "thumbnail" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_th.jpg" + } + }, + "type": "Feature", + "id": "K3A_20200508102646_28267_00027320_L1G", + "bbox": [ + 45.1496484, + 4.622519631, + 45.289144731, + 4.763075752 + ], + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 45.1496484, + 4.622562804 + ], + [ + 45.219367822, + 4.622544648 + ], + [ + 45.289086915, + 4.622519631 + ], + [ + 45.289144731, + 4.763031261 + ], + [ + 45.219411695, + 4.763057041 + ], + [ + 45.149678329, + 4.763075752 + ], + [ + 45.1496484, + 4.622562804 + ] + ] + ] + }, + "properties": { + "datetime": "2020-05-08T10:26:49.1019005+00:00", + "start_datetime": "2020-05-08T10:26:49.1019005+00:00", + "end_datetime": "2020-05-08T10:26:50.9661028+00:00", + "updated": "2020-09-30T06:17:41.7436478Z", + "platform": "kompsat-3a", + "constellation": "kompsat-3", + "mission": "kompsat-3", + "instruments": [ + "aeiss-a" + ], + "gsd": 0.55, + "title": "dummy", + "description": "dummy", + "eo:cloud_cover": 0.0, + "sat:absolute_orbit": 28267, + "proj:epsg": 32638, + "proj:wkt2": "PROJCS[\"WGS 84 / UTM zone 38N\", GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563, AUTHORITY[\"EPSG\", \"7030\"]], AUTHORITY[\"EPSG\", \"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.017453292519943295, AUTHORITY[\"EPSG\", \"9102\"]], AUTHORITY[\"EPSG\", \"4326\"]], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], PROJECTION[\"UTM38N\", AUTHORITY[\"EPSG\", \"32638\"]], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", 45], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000], PARAMETER[\"false_northing\", 0], AUTHORITY[\"EPSG\", \"32638\"], AXIS[\"East\", EAST], AXIS[\"North\", NORTH]]", + "view:off_nadir": 0.0, + "view:incidence_angle": 2.140217373, + "view:azimuth": 82.308110583, + "view:sun_azimuth": 300.8770745318308, + "view:sun_elevation": 64.28026701447693, + "proc:level": "Level1G", + "product_type": "PAN_MS_L1G" + } +} \ No newline at end of file diff --git a/src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G_missing_bands.json b/src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G_missing_bands.json new file mode 100644 index 00000000..a77345d3 --- /dev/null +++ b/src/DotNetStac.Test/Resources/Item/EoExtensionTests_K3A_20200508102646_28267_00027320_L1G_missing_bands.json @@ -0,0 +1,184 @@ +{ + "stac_extensions": [ + "eo", + "sat", + "proj", + "view" + ], + "stac_version": "1.0.0-beta.1", + "links": [ + { + "rel": "self", + "href": "K3A_20200508102646_28267_00027320_L1G.json" + } + ], + "assets": { + "metadata": { + "type": "text/xml", + "roles": [ + "metadata" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_Aux.xml" + }, + "MS1": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_B.tif", + "gsd": 2.2 + }, + "overview": { + "type": "image/jpeg", + "roles": [ + "overview" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_br.jpg" + }, + "MS2": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_G.tif", + "gsd": 2.2, + "eo:bands": [ + { + "name": "MS2", + "common_name": "green", + "center_wavelength": 0.56, + "scale": 40.16064257028113, + "offset": -14.021, + "eai": 1875.0 + } + ] + }, + "MS4": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_N.tif", + "gsd": 2.2, + "eo:bands": [ + { + "name": "MS4", + "common_name": "nir", + "center_wavelength": 0.83, + "scale": 76.92307692307692, + "offset": -10.2834, + "eai": 1027.0 + } + ] + }, + "PAN": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_P.tif", + "gsd": 0.55, + "eo:bands": [ + { + "name": "PAN", + "common_name": "pan", + "center_wavelength": 0.675 + } + ] + }, + "MS3": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_R.tif", + "gsd": 2.2, + "eo:bands": [ + { + "name": "MS3", + "common_name": "red", + "center_wavelength": 0.66, + "scale": 43.66812227074236, + "offset": -13.0457, + "eai": 1525.0 + } + ] + }, + "thumbnail": { + "type": "image/jpeg", + "roles": [ + "thumbnail" + ], + "href": "750-KARI-KOMPSAT3A-urn_ogc_def_EOP_KARI_KOMPSAT3_K3A_20200508102646_28267_00027320_L1G_Aux_xml.enclosure/K3A_20200508102646_28267_00027320_L1G_th.jpg" + } + }, + "type": "Feature", + "id": "K3A_20200508102646_28267_00027320_L1G", + "bbox": [ + 45.1496484, + 4.622519631, + 45.289144731, + 4.763075752 + ], + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 45.1496484, + 4.622562804 + ], + [ + 45.219367822, + 4.622544648 + ], + [ + 45.289086915, + 4.622519631 + ], + [ + 45.289144731, + 4.763031261 + ], + [ + 45.219411695, + 4.763057041 + ], + [ + 45.149678329, + 4.763075752 + ], + [ + 45.1496484, + 4.622562804 + ] + ] + ] + }, + "properties": { + "datetime": "2020-05-08T10:26:49.1019005+00:00", + "start_datetime": "2020-05-08T10:26:49.1019005+00:00", + "end_datetime": "2020-05-08T10:26:50.9661028+00:00", + "updated": "2020-09-30T06:17:41.7436478Z", + "platform": "kompsat-3a", + "constellation": "kompsat-3", + "mission": "kompsat-3", + "instruments": [ + "aeiss-a" + ], + "gsd": 0.55, + "title": "dummy", + "description": "dummy", + "eo:cloud_cover": 0.0, + "sat:absolute_orbit": 28267, + "proj:epsg": 32638, + "proj:wkt2": "PROJCS[\"WGS 84 / UTM zone 38N\", GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563, AUTHORITY[\"EPSG\", \"7030\"]], AUTHORITY[\"EPSG\", \"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.017453292519943295, AUTHORITY[\"EPSG\", \"9102\"]], AUTHORITY[\"EPSG\", \"4326\"]], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], PROJECTION[\"UTM38N\", AUTHORITY[\"EPSG\", \"32638\"]], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", 45], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000], PARAMETER[\"false_northing\", 0], AUTHORITY[\"EPSG\", \"32638\"], AXIS[\"East\", EAST], AXIS[\"North\", NORTH]]", + "view:off_nadir": 0.0, + "view:incidence_angle": 2.140217373, + "view:azimuth": 82.308110583, + "view:sun_azimuth": 300.8770745318308, + "view:sun_elevation": 64.28026701447693, + "proc:level": "Level1G", + "product_type": "PAN_MS_L1G" + } +} \ No newline at end of file diff --git a/src/DotNetStac/Extensions/Eo/EoStacExtension.cs b/src/DotNetStac/Extensions/Eo/EoStacExtension.cs index ad4312f7..07edf6a4 100644 --- a/src/DotNetStac/Extensions/Eo/EoStacExtension.cs +++ b/src/DotNetStac/Extensions/Eo/EoStacExtension.cs @@ -25,18 +25,18 @@ public EoStacExtension() : base("eo") { } - public void AddBandObject(StacAsset stacAsset, EoBandObject eoBandObject) + public void AddBandObject(StacAsset stacAsset, EoBandObject[] eoBandObject) { string key = Id + ":" + BandsField; stacAsset.Properties.Remove(key); stacAsset.Properties.Add(key, eoBandObject); } - public EoBandObject GetBandObject(StacAsset stacAsset) + public EoBandObject[] GetBandObject(StacAsset stacAsset) { string key = Id + ":" + BandsField; if (stacAsset.Properties.ContainsKey(key)) - return (EoBandObject)stacAsset.Properties[key]; + return (EoBandObject[])stacAsset.Properties[key]; return null; } } diff --git a/src/DotNetStac/Extensions/Projection/ProjectionStacExtension.cs b/src/DotNetStac/Extensions/Projection/ProjectionStacExtension.cs index 479b160c..662fe62e 100644 --- a/src/DotNetStac/Extensions/Projection/ProjectionStacExtension.cs +++ b/src/DotNetStac/Extensions/Projection/ProjectionStacExtension.cs @@ -7,7 +7,7 @@ using Stac.Extensions; using Stac.Item; -namespace Stac.Extensions.Eo +namespace Stac.Extensions.Projection { public class ProjectionStacExtension : AssignableStacExtension, IStacExtension { diff --git a/src/DotNetStac/Extensions/StacExtensions.cs b/src/DotNetStac/Extensions/StacExtensions.cs index 838614d3..d1699f44 100644 --- a/src/DotNetStac/Extensions/StacExtensions.cs +++ b/src/DotNetStac/Extensions/StacExtensions.cs @@ -73,9 +73,9 @@ public IStacExtension this[string key] get => stacExtensions.FirstOrDefault(e => e.Id == key); } - public IStacExtension GetExtension() where T : IStacExtension + public T GetExtension() where T : IStacExtension { - return stacExtensions.FirstOrDefault(e => e is T); + return (T)stacExtensions.FirstOrDefault(e => e is T); } } } \ No newline at end of file diff --git a/src/DotNetStac/Extensions/StacExtensionsFactory.cs b/src/DotNetStac/Extensions/StacExtensionsFactory.cs index 07bf1db6..8ded30b0 100644 --- a/src/DotNetStac/Extensions/StacExtensionsFactory.cs +++ b/src/DotNetStac/Extensions/StacExtensionsFactory.cs @@ -17,6 +17,9 @@ public StacExtensionsFactory(Dictionary stacExtensions) internal StacExtensionsFactory() { this.stacExtensionsDictionary.Add("sat", typeof(Sat.SatStacExtension)); + this.stacExtensionsDictionary.Add("eo", typeof(Eo.EoStacExtension)); + this.stacExtensionsDictionary.Add("view", typeof(View.ViewStacExtension)); + this.stacExtensionsDictionary.Add("proj", typeof(Projection.ProjectionStacExtension)); } public static StacExtensionsFactory Default diff --git a/src/DotNetStac/Extensions/View/ViewStacExtension.cs b/src/DotNetStac/Extensions/View/ViewStacExtension.cs index 8856b483..fcae0dfc 100644 --- a/src/DotNetStac/Extensions/View/ViewStacExtension.cs +++ b/src/DotNetStac/Extensions/View/ViewStacExtension.cs @@ -6,7 +6,7 @@ using Stac.Extensions; using Stac.Item; -namespace Stac.Extensions.Sat +namespace Stac.Extensions.View { public class ViewStacExtension : AssignableStacExtension, IStacExtension {