Skip to content

Commit

Permalink
Corrections for Vision-1 and related functionality (3)
Browse files Browse the repository at this point in the history
  • Loading branch information
floeschau committed Mar 6, 2024
1 parent 765de21 commit 65535a6
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
"coordinates": [
[
[
119.73348,
-0.71703
],
[
119.73348,
-0.95943
119.73346,
-0.95942
],
[
119.9743,
Expand All @@ -31,8 +27,12 @@
-0.71703
],
[
119.73348,
-0.71703
119.73346,
-0.71701
],
[
119.73346,
-0.95942
]
]
]
Expand Down Expand Up @@ -76,10 +76,10 @@
]
},
"bbox": [
119.73348,
119.73346,
-0.95943,
119.9743,
-0.71703
-0.71701
],
"assets": {
"PAN-ORT": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
"coordinates": [
[
[
119.77077,
-0.90282
],
[
119.77077,
-1.1372
119.77075,
-1.13719
],
[
120.01001,
Expand All @@ -31,8 +27,12 @@
-0.90282
],
[
119.77077,
-0.90282
119.77075,
-0.9028
],
[
119.77075,
-1.13719
]
]
]
Expand Down Expand Up @@ -76,10 +76,10 @@
]
},
"bbox": [
119.77077,
119.77075,
-1.1372,
120.01001,
-0.90282
-0.9028
],
"assets": {
"PAN-PRJ": {
Expand Down
85 changes: 74 additions & 11 deletions src/Stars.Data/Model/Metadata/Dimap/DimapMetadataExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,85 @@ private void AddOtherProperties(DimapProfiler dimapProfiler, IDictionary<string,

private GeoJSON.Net.Geometry.IGeometryObject GetGeometry(DimapProfiler dimapProfiler)
{
List<GeoJSON.Net.Geometry.Position> positions = new List<Position>();
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<GeoJSON.Net.Geometry.Position> positions = new List<Position>();
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<GeoJSON.Net.Geometry.Position> positions = new List<Position>();
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<GeoJSON.Net.Geometry.Position> sorted = new List<GeoJSON.Net.Geometry.Position>(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)
Expand Down Expand Up @@ -378,7 +442,6 @@ protected void AddAssets(StacItem stacItem, IItem item, DimapProfiler dimapProfi
private KeyValuePair<string, StacAsset> 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));
Expand Down

0 comments on commit 65535a6

Please sign in to comment.