2023-04-06 14:46:08 +02:00
|
|
|
using System.Text.Json.Serialization;
|
2023-04-06 01:29:45 +02:00
|
|
|
using OSMDatastructure.Graph;
|
2023-04-06 14:27:25 +02:00
|
|
|
using Pathfinding;
|
2023-04-06 01:29:45 +02:00
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-09 16:47:33 +02:00
|
|
|
app.MapGet("/getRouteDistance", (float latStart, float lonStart, float latEnd, float lonEnd) =>
|
2023-04-06 01:29:45 +02:00
|
|
|
{
|
2023-04-09 16:17:15 +02:00
|
|
|
DateTime startCalc = DateTime.Now;
|
|
|
|
List<PathNode> result = Pathfinder.AStarDistance("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd));
|
2023-04-09 16:29:09 +02:00
|
|
|
PathResult pathResult = new PathResult(DateTime.Now - startCalc, result);
|
2023-04-06 14:46:08 +02:00
|
|
|
return pathResult;
|
2023-04-06 01:29:45 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-04-09 16:47:33 +02:00
|
|
|
app.MapGet("/getRouteTime", (float latStart, float lonStart, float latEnd, float lonEnd) =>
|
|
|
|
{
|
|
|
|
DateTime startCalc = DateTime.Now;
|
|
|
|
List<PathNode> result = Pathfinder.AStarTime("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd), Tag.SpeedType.car);
|
|
|
|
PathResult pathResult = new PathResult(DateTime.Now - startCalc, result);
|
|
|
|
return pathResult;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-04-06 14:33:00 +02:00
|
|
|
app.MapGet("/getClosestNode", (float lat, float lon) =>
|
|
|
|
{
|
|
|
|
RegionManager regionManager = new RegionManager("D:/stuttgart-regbez-latest");
|
2023-04-09 16:41:42 +02:00
|
|
|
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.road);
|
2023-04-06 14:33:00 +02:00
|
|
|
});
|
|
|
|
|
2023-04-06 01:29:45 +02:00
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
2023-04-06 14:46:08 +02:00
|
|
|
app.Run();
|
|
|
|
|
|
|
|
internal class PathResult
|
|
|
|
{
|
|
|
|
[JsonInclude]public TimeSpan calcTime;
|
2023-04-09 16:29:09 +02:00
|
|
|
[JsonInclude] public double pathWeight = double.PositiveInfinity;
|
|
|
|
[JsonInclude] public double pathTravelDistance = double.PositiveInfinity;
|
2023-04-06 14:46:08 +02:00
|
|
|
[JsonInclude]public List<PathNode> pathNodes;
|
|
|
|
|
|
|
|
public PathResult(TimeSpan calcTime, List<PathNode> pathNodes)
|
|
|
|
{
|
|
|
|
this.calcTime = calcTime;
|
|
|
|
this.pathNodes = pathNodes;
|
2023-04-09 16:29:09 +02:00
|
|
|
if (pathNodes.Count > 0)
|
|
|
|
{
|
|
|
|
this.pathWeight = pathNodes.Last().currentPathWeight;
|
|
|
|
this.pathTravelDistance = pathNodes.Last().currentPathLength;
|
|
|
|
}
|
2023-04-06 14:46:08 +02:00
|
|
|
}
|
|
|
|
}
|