diff --git a/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_ORT_103091_14e5.json b/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_ORT_103091_14e5.json index fef0c9fa..38429b69 100644 --- a/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_ORT_103091_14e5.json +++ b/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_ORT_103091_14e5.json @@ -15,12 +15,8 @@ "coordinates": [ [ [ - 119.73348, - -0.71703 - ], - [ - 119.73348, - -0.95943 + 119.73346, + -0.95942 ], [ 119.9743, @@ -31,8 +27,12 @@ -0.71703 ], [ - 119.73348, - -0.71703 + 119.73346, + -0.71701 + ], + [ + 119.73346, + -0.95942 ] ] ] @@ -76,10 +76,10 @@ ] }, "bbox": [ - 119.73348, + 119.73346, -0.95943, 119.9743, - -0.71703 + -0.71701 ], "assets": { "PAN-ORT": { diff --git a/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_PRJ_103935_14e5.json b/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_PRJ_103935_14e5.json index 3a651951..09c32e91 100644 --- a/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_PRJ_103935_14e5.json +++ b/src/Stars.Data.Tests/Resources/DMC/Vision-1/BUN/MetadataExtractorsTests_VIS1_20200722023318_PRJ_103935_14e5.json @@ -15,12 +15,8 @@ "coordinates": [ [ [ - 119.77077, - -0.90282 - ], - [ - 119.77077, - -1.1372 + 119.77075, + -1.13719 ], [ 120.01001, @@ -31,8 +27,12 @@ -0.90282 ], [ - 119.77077, - -0.90282 + 119.77075, + -0.9028 + ], + [ + 119.77075, + -1.13719 ] ] ] @@ -76,10 +76,10 @@ ] }, "bbox": [ - 119.77077, + 119.77075, -1.1372, 120.01001, - -0.90282 + -0.9028 ], "assets": { "PAN-PRJ": { diff --git a/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs index 27547119..e62c5186 100644 --- a/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs @@ -288,21 +288,85 @@ private void AddOtherProperties(DimapProfiler dimapProfiler, IDictionary positions = new List(); - foreach (var vertex in dimapProfiler.Dimap.Dataset_Frame) + GeoJSON.Net.Geometry.IGeometryObject geometry; + + if (dimapProfiler.Dimaps.Length == 1) { - positions.Add(new GeoJSON.Net.Geometry.Position( - vertex.FRAME_LAT.Value, vertex.FRAME_LON.Value - ) + List positions = new List(); + foreach (var vertex in dimapProfiler.Dimap.Dataset_Frame) + { + positions.Add(new GeoJSON.Net.Geometry.Position(vertex.FRAME_LAT.Value, vertex.FRAME_LON.Value)); + } + positions.Add(positions.First()); + + GeoJSON.Net.Geometry.LineString lineString = new GeoJSON.Net.Geometry.LineString( + positions.ToArray() ); + + geometry = new GeoJSON.Net.Geometry.Polygon(new GeoJSON.Net.Geometry.LineString[] { lineString }).NormalizePolygon(); } - positions.Add(positions.First()); + else + { + double minLon = 180; + double maxLon = -180; + GeoJSON.Net.Geometry.Position swPosition = null, sePosition = null, nePosition = null, nwPosition = null; - GeoJSON.Net.Geometry.LineString lineString = new GeoJSON.Net.Geometry.LineString( - positions.ToArray() - ); + foreach (Schemas.DimapDocument dimap in dimapProfiler.Dimaps) + { + List positions = new List(); + foreach (var vertex in dimap.Dataset_Frame) + { + positions.Add(new GeoJSON.Net.Geometry.Position(vertex.FRAME_LAT.Value, vertex.FRAME_LON.Value)); + } + if (positions.Count != 4) return null; + + List sorted = new List(positions); + sorted.Sort((pos1, pos2) => { + if (pos1.Longitude < pos2.Longitude) return -1; + if (pos1.Longitude > pos2.Longitude) return 1; + return 0; + }); + if (sorted[0].Longitude < minLon) + { + minLon = sorted[0].Longitude; + if (sorted[0].Latitude < sorted[1].Latitude) + { + swPosition = sorted[0]; + nwPosition = sorted[1]; + } + else + { + nwPosition = sorted[0]; + swPosition = sorted[1]; + } + } + if (sorted[3].Longitude > maxLon) + { + maxLon = sorted[3].Longitude; + if (sorted[2].Latitude < sorted[3].Latitude) + { + sePosition = sorted[2]; + nePosition = sorted[3]; + } + else + { + nePosition = sorted[2]; + sePosition = sorted[3]; + } + } + } + + GeoJSON.Net.Geometry.LineString lineString = new GeoJSON.Net.Geometry.LineString( + new GeoJSON.Net.Geometry.Position[] + { + swPosition, sePosition, nePosition, nwPosition, swPosition + } + ); + + geometry = new GeoJSON.Net.Geometry.Polygon(new GeoJSON.Net.Geometry.LineString[] { lineString }).NormalizePolygon(); + } - return new GeoJSON.Net.Geometry.Polygon(new GeoJSON.Net.Geometry.LineString[] { lineString }).NormalizePolygon(); + return geometry; } protected void AddAssets(StacItem stacItem, IItem item, DimapProfiler dimapProfiler) @@ -378,7 +442,6 @@ protected void AddAssets(StacItem stacItem, IItem item, DimapProfiler dimapProfi private KeyValuePair CreateRasterAsset(StacItem stacItem, IAsset bandAsset, DimapProfiler dimapProfiler, t_Data_File dataFile, Schemas.DimapDocument dimap) { string mimeType; - Console.WriteLine("EXT = {0}", Path.GetExtension(bandAsset.Uri.AbsolutePath)); if (Path.GetExtension(bandAsset.Uri.AbsolutePath) == ".jp2") mimeType = "image/jpeg"; else mimeType = MimeTypes.GetMimeType(Path.GetFileName(bandAsset.Uri.AbsolutePath)); StacAsset stacAsset = StacAsset.CreateDataAsset(stacItem, bandAsset.Uri, new ContentType(mimeType));