Skip to content

Commit

Permalink
Sprint release 11 (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corgam authored Jul 10, 2024
2 parents dce6fc0 + c40d507 commit 3e3cf2d
Show file tree
Hide file tree
Showing 140 changed files with 1,670 additions and 670 deletions.
12 changes: 8 additions & 4 deletions backend/api-gateway/Models/LocationData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace APIGateway.Models
using System.Text.Json.Serialization;

namespace APIGateway.Models
{
public class LocationDataRequest
{
public string DatasetId { get; set; } = string.Empty;
public List<Coordinate> Location { get; set; } = new List<Coordinate>();
[JsonPropertyName("datasetId")]
public string DatasetId { get; set; }
[JsonPropertyName("location")]
public List<List<List<double>>> Location { get; set; }
}

public class Coordinate
Expand All @@ -14,7 +18,7 @@ public class Coordinate

public class LocationDataResponse
{
public List<DatasetItem> CurrentDatasetData { get; set; } = new List<DatasetItem>();
public List<DatasetItem> IndividualData { get; set; } = new List<DatasetItem>();
public List<DatasetItem> GeneralData { get; set; } = new List<DatasetItem>();
}

Expand Down
17 changes: 17 additions & 0 deletions backend/metadata-database/init-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ const datasets = [
Tables: [],
},
},
{
basicData: {
DatasetId: "building_models",
Name: "Building Models",
ShortDescription: `Simplified 3D building models.`,
Icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M136.83,220.43a8,8,0,0,1-11.09,2.23A183.15,183.15,0,0,0,24,192a8,8,0,0,1,0-16,199.11,199.11,0,0,1,110.6,33.34A8,8,0,0,1,136.83,220.43ZM24,144a8,8,0,0,0,0,16,214.81,214.81,0,0,1,151.17,61.71,8,8,0,1,0,11.2-11.42A230.69,230.69,0,0,0,24,144Zm208,16a216.51,216.51,0,0,0-48.59,5.49q8.24,6.25,16,13.16A201.53,201.53,0,0,1,232,176a8,8,0,0,1,0,16c-6,0-11.93.29-17.85.86q8.32,8.67,15.94,18.14a8,8,0,1,1-12.48,10A247,247,0,0,0,24,128a8,8,0,0,1,0-16,266.33,266.33,0,0,1,48,4.37V80a8,8,0,0,1,3.2-6.4l64-48a8,8,0,0,1,9.6,0l64,48A8,8,0,0,1,216,80v32.49c5.31-.31,10.64-.49,16-.49a8,8,0,0,1,0,16,246.3,246.3,0,0,0-84.26,14.69q9.44,5,18.46,10.78A232.2,232.2,0,0,1,232,144a8,8,0,0,1,0,16ZM120,88h48a8,8,0,0,1,8,8v21.94q11.88-2.56,24-4V84L144,42,88,84v35.81q12.19,3,24,7.18V96A8,8,0,0,1,120,88Zm8.07,45.27A262.48,262.48,0,0,1,160,121.94V104H128v29.24Z"></path></svg>',
},
additionalData: {
Icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M136.83,220.43a8,8,0,0,1-11.09,2.23A183.15,183.15,0,0,0,24,192a8,8,0,0,1,0-16,199.11,199.11,0,0,1,110.6,33.34A8,8,0,0,1,136.83,220.43ZM24,144a8,8,0,0,0,0,16,214.81,214.81,0,0,1,151.17,61.71,8,8,0,1,0,11.2-11.42A230.69,230.69,0,0,0,24,144Zm208,16a216.51,216.51,0,0,0-48.59,5.49q8.24,6.25,16,13.16A201.53,201.53,0,0,1,232,176a8,8,0,0,1,0,16c-6,0-11.93.29-17.85.86q8.32,8.67,15.94,18.14a8,8,0,1,1-12.48,10A247,247,0,0,0,24,128a8,8,0,0,1,0-16,266.33,266.33,0,0,1,48,4.37V80a8,8,0,0,1,3.2-6.4l64-48a8,8,0,0,1,9.6,0l64,48A8,8,0,0,1,216,80v32.49c5.31-.31,10.64-.49,16-.49a8,8,0,0,1,0,16,246.3,246.3,0,0,0-84.26,14.69q9.44,5,18.46,10.78A232.2,232.2,0,0,1,232,144a8,8,0,0,1,0,16ZM120,88h48a8,8,0,0,1,8,8v21.94q11.88-2.56,24-4V84L144,42,88,84v35.81q12.19,3,24,7.18V96A8,8,0,0,1,120,88Zm8.07,45.27A262.48,262.48,0,0,1,160,121.94V104H128v29.24Z"></path></svg>',
Type: "areas",
LongDescription: `The building models have a 3D object of each building plus additional information on its dimentions.`,
MinZoomLevel: 11,
MarkersThreshold: 17,
DisplayProperty: "",
Tables: [],
},
},
];

// Iterate over datasets and insert only if DatasetId does not exist
Expand Down
105 changes: 104 additions & 1 deletion backend/src/BIE.Core/BIE.Core.API/ApiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,83 @@
using Accord.Math;
using BIE.Core.API.Controllers;
using BieMetadata;
using NetTopologySuite.Geometries;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;
using ProjNet.IO.CoordinateSystems;

namespace BIE.Core.API;

public static class ApiHelper
{
private static CultureInfo sCultureInfo = new CultureInfo("en-US");
private static string epsg27700 = @"PROJCS[""North_America_Albers_Equal_Area_Conic"",
GEOGCS[""NAD83"",
DATUM[""North_American_Datum_1983"",
SPHEROID[""GRS 1980"",6378137,298.257222101,
AUTHORITY[""EPSG"",""7019""]],
AUTHORITY[""EPSG"",""6269""]],
PRIMEM[""Greenwich"",0,
AUTHORITY[""EPSG"",""8901""]],
UNIT[""degree"",0.0174532925199433,
AUTHORITY[""EPSG"",""9122""]],
AUTHORITY[""EPSG"",""4269""]],
PROJECTION[""Albers_Conic_Equal_Area""],
PARAMETER[""latitude_of_center"",40],
PARAMETER[""longitude_of_center"",-96],
PARAMETER[""standard_parallel_1"",20],
PARAMETER[""standard_parallel_2"",60],
PARAMETER[""false_easting"",0],
PARAMETER[""false_northing"",0],
UNIT[""metre"",1,
AUTHORITY[""EPSG"",""9001""]],
AXIS[""Easting"",EAST],
AXIS[""Northing"",NORTH],
AUTHORITY[""ESRI"",""102008""]
"; // see http://epsg.io/27700
private static ICoordinateTransformation mTransformation = new CoordinateTransformationFactory().
CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84,
(CoordinateSystem)CoordinateSystemWktReader.Parse(epsg27700));

public static double getDistance(double longitude, double latitude, Point p)
{
double[] sourceInWGS84_arr = { longitude, latitude };
double[] sourceInEPSG27700_arr = mTransformation.MathTransform.Transform(sourceInWGS84_arr);
Coordinate sourceInEPSG27700 = new Coordinate(sourceInEPSG27700_arr[0], sourceInEPSG27700_arr[1]);

double[] targetPointInWGS84 = { p.Y, p.X };
double[] targetPointInEpsg27700 = mTransformation.MathTransform.Transform(targetPointInWGS84);
Coordinate targetInEPSG27700 = new Coordinate(targetPointInEpsg27700[0], targetPointInEpsg27700[1]);
var distance = sourceInEPSG27700.Distance(targetInEPSG27700);
return distance;
}

public static double getArea(Polygon p)
{
// convert each point of the polygon into a new coordinate (revert x and y
// convert it into EPSG27700
// return area
var coordinates = p.Coordinates;
Console.WriteLine($"coordinates {coordinates}");
var transformedCoordinates = new Coordinate[coordinates.Length];
// Transform each coordinate
for (int i = 0; i < coordinates.Length; i++)
{
double[] pointWGS84 = { coordinates[i].Y, coordinates[i].X }; // Switch X and Y
double[] pointEPSG27700 = mTransformation.MathTransform.Transform(pointWGS84);
transformedCoordinates[i] = new Coordinate(pointEPSG27700[0], pointEPSG27700[1]);
Console.WriteLine($"transformedCoordinates[i] {transformedCoordinates[i]}");
}
var geometryFactory = new GeometryFactory(new PrecisionModel(), 27700);
var transformedPolygon = new Polygon(new LinearRing(transformedCoordinates), geometryFactory);
Console.WriteLine($"area {transformedPolygon.Area}");
Console.WriteLine($"transformed coords {transformedPolygon.Coordinates}");



// Return the area of the transformed polygon
return transformedPolygon.Area;
}

/// <summary>
/// Get the Bounding Box from the query parameters.
Expand Down Expand Up @@ -53,6 +124,38 @@ public static string GetPolygonFromBoundingBox(BoundingBox boundingBox)
$" {bottomLong} {bottomLat}))";
}

public static List<string> ConvertToWktPolygons(List<List<List<double>>> locations)
{
var culture = new CultureInfo("en-US");
var wktPolygons = new List<string>();

foreach (var polygon in locations)
{
var wktString = "POLYGON((";
foreach (var point in polygon)
{
if (point.Count != 2)
{
throw new ArgumentException("Each point should have exactly two coordinates.");
}

var longitude = point[0].ToString(culture);
var latitude = point[1].ToString(culture);
wktString += $"{longitude} {latitude}, ";
}

// Close the polygon by repeating the first point
var firstPoint = polygon[0];
var firstLongitude = firstPoint[0].ToString(culture);
var firstLatitude = firstPoint[1].ToString(culture);
wktString += $"{firstLongitude} {firstLatitude}))";

wktPolygons.Add(wktString);
}

return wktPolygons;
}

/// <summary>
/// Get the polygon of the bounding box given in the queryparameters
/// </summary>
Expand Down Expand Up @@ -84,7 +187,7 @@ public static bool BoxIntersection(BoundingBox box1, BoundingBox box2)
var right2 = box2.maxX;
var top2 = box2.maxY;

Console.WriteLine($"left1: {left1}, left2: {left2}");
//Console.WriteLine($"left1: {left1}, left2: {left2}");

return !(right1 < left2 || right2 < left1 || top1 < bottom2 || top2 < bottom1);
}
Expand Down
2 changes: 2 additions & 0 deletions backend/src/BIE.Core/BIE.Core.API/BIE.Core.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<PackageReference Include="Accord.Math" Version="3.8.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="MongoDB.Driver" Version="2.26.0" />
<PackageReference Include="NetTopologySuite" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="ProjNet" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 3e3cf2d

Please sign in to comment.