From d50d9506491bdcd9c59e05d9a4e140ea02859033 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Sun, 13 Dec 2020 20:38:19 +0100 Subject: [PATCH] fixed getAssetBands --- src/DotNetStac.Test/Item/EoExtensionTests.cs | 26 ++ ..._K3_20201112193439_45302_18521139_L1G.json | 257 ++++++++++++++++++ .../Extensions/Eo/EoStacExtension.cs | 2 +- 3 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 src/DotNetStac.Test/Resources/Item/EoExtensionTests_GetAssetsBands_K3_20201112193439_45302_18521139_L1G.json diff --git a/src/DotNetStac.Test/Item/EoExtensionTests.cs b/src/DotNetStac.Test/Item/EoExtensionTests.cs index 7d02f1a2..5897672f 100644 --- a/src/DotNetStac.Test/Item/EoExtensionTests.cs +++ b/src/DotNetStac.Test/Item/EoExtensionTests.cs @@ -52,6 +52,32 @@ public void SetAssetBands() } + [Fact] + public void GetAssetsBands() + { + var k3CompleteJson = GetJson("Item", "GetAssetsBands_K3_20201112193439_45302_18521139_L1G"); + + StacItem k3complete = JsonConvert.DeserializeObject(k3CompleteJson); + + EoStacExtension k3EOext = k3complete.GetExtension(); + + Assert.NotNull(k3EOext); + + var overviewAssets = k3complete.Assets.Where(a => + { + var bands = k3EOext.GetAssetBandObjects(a.Value); + if (a.Value.Properties.ContainsKey("eo:bands")) + { + Assert.NotNull(bands); + Assert.NotEmpty(bands); + return bands.Any(band => !string.IsNullOrEmpty(band.Name)); + } + return false; + }); + + Assert.Equal(5, overviewAssets.Count()); + } + [Fact] public void CreateEoExtension() { diff --git a/src/DotNetStac.Test/Resources/Item/EoExtensionTests_GetAssetsBands_K3_20201112193439_45302_18521139_L1G.json b/src/DotNetStac.Test/Resources/Item/EoExtensionTests_GetAssetsBands_K3_20201112193439_45302_18521139_L1G.json new file mode 100644 index 00000000..a66c9909 --- /dev/null +++ b/src/DotNetStac.Test/Resources/Item/EoExtensionTests_GetAssetsBands_K3_20201112193439_45302_18521139_L1G.json @@ -0,0 +1,257 @@ +{ + "stac_extensions": [ + "disaster", + "eo", + "sat", + "proj", + "view" + ], + "stac_version": "1.0.0-beta.2", + "links": [ + { + "type": "application/json; profile=stac-item", + "rel": "derived_from", + "href": "786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml.json" + }, + { + "type": "application/json; profile=stac-item", + "rel": "self", + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/K3_20201112193439_45302_18521139_L1G.json" + }, + { + "type": "application/json; profile=stac-catalog", + "rel": "root", + "href": "http://localhost:8082/catalog/catalog.json" + } + ], + "assets": { + "metadata": { + "type": "text/xml", + "roles": [ + "metadata" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_Aux.xml" + }, + "MS1": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_B.tif", + "gsd": 2.8, + "eo:bands": [ + { + "name": "MS1", + "common_name": "blue", + "center_wavelength": 0.07, + "scale": 36.36363636363637, + "offset": -28.4989, + "eai": 2001.0 + } + ] + }, + "overview": { + "type": "image/jpeg", + "roles": [ + "overview" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_br.jpg" + }, + "MS2": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_G.tif", + "gsd": 2.8, + "eo:bands": [ + { + "name": "MS2", + "common_name": "green", + "center_wavelength": 0.08, + "scale": 26.17801047120419, + "offset": -27.3846, + "eai": 1875.0 + } + ] + }, + "MS4": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_N.tif", + "gsd": 2.8, + "eo:bands": [ + { + "name": "MS4", + "common_name": "nir", + "center_wavelength": 0.14, + "scale": 52.083333333333336, + "offset": -13.591, + "eai": 1027.0 + } + ] + }, + "PAN": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_P.tif", + "gsd": 0.7, + "eo:bands": [ + { + "name": "PAN", + "common_name": "pan", + "center_wavelength": 0.45 + } + ] + }, + "MS3": { + "type": "image/tiff", + "roles": [ + "data" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_R.tif", + "gsd": 2.8, + "eo:bands": [ + { + "name": "MS3", + "common_name": "red", + "center_wavelength": 0.06, + "scale": 34.013605442176875, + "offset": -21.6854, + "eai": 1525.0 + } + ] + }, + "thumbnail": { + "type": "image/jpeg", + "roles": [ + "thumbnail" + ], + "href": "http://localhost:8082/catalog/acquisitions/call-786/786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml/urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml-product/K3_20201112193439_45302_18521139_L1G_th.jpg" + } + }, + "type": "Feature", + "id": "K3_20201112193439_45302_18521139_L1G", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -92.64663661, + 18.576395368 + ], + [ + -92.529930348, + 18.57614059 + ], + [ + -92.413226243, + 18.575813599 + ], + [ + -92.412722213, + 18.722456862 + ], + [ + -92.529526555, + 18.722786621 + ], + [ + -92.646333063, + 18.723043555 + ], + [ + -92.64663661, + 18.576395368 + ] + ] + ] + }, + "properties": { + "datetime": "2020-11-12T20:34:47.8741569+01:00", + "start_datetime": "2020-11-12T20:34:47.8741569+01:00", + "end_datetime": "2020-11-12T20:34:50.2062721+01:00", + "updated": "2020-12-13T19:01:45.790996Z", + "platform": "kompsat-3", + "constellation": "kompsat-3", + "mission": "kompsat-3", + "instruments": [ + "aeiss" + ], + "gsd": 0.7, + "title": "dummy", + "description": "
\n\n### dummy\n\n* Platform **kompsat-3**\n* Instruments **aeiss**\n* Sensing Time **[11/12/2020 20:34:47]**\n* Created **1/1/0001 12:00:00 AM**\n* Updated **12/13/2020 7:01:45 PM**\n", + "eo:cloud_cover": 0.0, + "sat:absolute_orbit": 45302, + "sat:relative_orbit": 45302, + "sat:orbit_state": "ascending", + "proj:epsg": 32615, + "proj:wkt2": "PROJCS[\"WGS 84 / UTM zone 15N\", 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[\"UTM15N\", AUTHORITY[\"EPSG\", \"32615\"]], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", -93], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000], PARAMETER[\"false_northing\", 0], AUTHORITY[\"EPSG\", \"32615\"], AXIS[\"East\", EAST], AXIS[\"North\", NORTH]]", + "view:off_nadir": 30.864219939, + "view:incidence_angle": 34.605545581, + "view:azimuth": 318.194222473, + "view:sun_azimuth": 212.9437888826261, + "view:sun_elevation": 46.962222523232704, + "proc:level": "Level1G", + "product_type": "PAN_MS_L1G", + "eo:bands": [ + { + "name": "MS1", + "common_name": "blue", + "center_wavelength": 0.07, + "scale": 36.36363636363637, + "offset": -28.4989, + "eai": 2001.0 + }, + { + "name": "MS2", + "common_name": "green", + "center_wavelength": 0.08, + "scale": 26.17801047120419, + "offset": -27.3846, + "eai": 1875.0 + }, + { + "name": "MS4", + "common_name": "nir", + "center_wavelength": 0.14, + "scale": 52.083333333333336, + "offset": -13.591, + "eai": 1027.0 + }, + { + "name": "PAN", + "common_name": "pan", + "center_wavelength": 0.45 + }, + { + "name": "MS3", + "common_name": "red", + "center_wavelength": 0.06, + "scale": 34.013605442176875, + "offset": -21.6854, + "eai": 1525.0 + } + ], + "disaster:class": "Acquisition", + "status": { + "stage": "dataset", + "message": null + }, + "disaster:call_ids": [ + 786 + ], + "cos2:xml": null, + "cos2:id": "786-KARI-KOMPSAT3-urn_ogc_def_EOP_KARI_KOMPSAT3_K3_20201112193439_45302_18521139_L1G_Aux_xml" + }, + "bbox": [ + -92.64663661, + 18.575813599, + -92.412722213, + 18.723043555 + ] +} \ No newline at end of file diff --git a/src/DotNetStac/Extensions/Eo/EoStacExtension.cs b/src/DotNetStac/Extensions/Eo/EoStacExtension.cs index 30afcc0d..c0687e1b 100644 --- a/src/DotNetStac/Extensions/Eo/EoStacExtension.cs +++ b/src/DotNetStac/Extensions/Eo/EoStacExtension.cs @@ -35,7 +35,7 @@ public EoBandObject[] GetAssetBandObjects(StacAsset stacAsset) { string key = Id + ":" + BandsField; if (stacAsset.Properties.ContainsKey(key)) - return (EoBandObject[])stacAsset.Properties[key]; + return stacAsset.GetProperty(key); return null; }