route stitching

This commit is contained in:
Anton Martynenko
2025-11-01 16:54:46 +01:00
parent 8714a4817d
commit 11395ec913
15 changed files with 698 additions and 10 deletions
+44 -6
View File
@@ -10,14 +10,17 @@ namespace SatelliteProvider.Services;
public class RouteService : IRouteService
{
private readonly IRouteRepository _routeRepository;
private readonly IRegionService _regionService;
private readonly ILogger<RouteService> _logger;
private const double MAX_POINT_SPACING_METERS = 200.0;
public RouteService(
IRouteRepository routeRepository,
IRegionService regionService,
ILogger<RouteService> logger)
{
_routeRepository = routeRepository;
_regionService = regionService;
_logger = logger;
}
@@ -54,10 +57,10 @@ public class RouteService : IRouteService
var geoPoint = new GeoPoint(currentPoint.Latitude, currentPoint.Longitude);
double? distanceFromPrevious = null;
if (segmentIndex > 0)
if (allPoints.Count > 0)
{
var prevPoint = request.Points[segmentIndex - 1];
var prevGeoPoint = new GeoPoint(prevPoint.Latitude, prevPoint.Longitude);
var lastAddedPoint = allPoints[^1];
var prevGeoPoint = new GeoPoint(lastAddedPoint.Latitude, lastAddedPoint.Longitude);
distanceFromPrevious = GeoUtils.CalculateDistance(prevGeoPoint, geoPoint);
totalDistance += distanceFromPrevious.Value;
}
@@ -87,9 +90,8 @@ public class RouteService : IRouteService
foreach (var intermediateGeo in intermediatePoints)
{
var prevGeo = sequenceNumber == 1 ? startGeo : new GeoPoint(
allPoints[sequenceNumber - 1].Latitude,
allPoints[sequenceNumber - 1].Longitude);
var lastAddedPoint = allPoints[^1];
var prevGeo = new GeoPoint(lastAddedPoint.Latitude, lastAddedPoint.Longitude);
var distFromPrev = GeoUtils.CalculateDistance(prevGeo, intermediateGeo);
totalDistance += distFromPrev;
@@ -120,6 +122,8 @@ public class RouteService : IRouteService
ZoomLevel = request.ZoomLevel,
TotalDistanceMeters = totalDistance,
TotalPoints = allPoints.Count,
RequestMaps = request.RequestMaps,
MapsReady = false,
CreatedAt = now,
UpdatedAt = now
};
@@ -141,6 +145,30 @@ public class RouteService : IRouteService
await _routeRepository.InsertRoutePointsAsync(pointEntities);
if (request.RequestMaps)
{
_logger.LogInformation("Route {RouteId}: Requesting regions for all {Count} points",
request.Id, allPoints.Count);
foreach (var point in allPoints)
{
var regionId = Guid.NewGuid();
await _regionService.RequestRegionAsync(
regionId,
point.Latitude,
point.Longitude,
request.RegionSizeMeters,
request.ZoomLevel,
stitchTiles: false);
await _routeRepository.LinkRouteToRegionAsync(request.Id, regionId);
}
_logger.LogInformation("Route {RouteId}: {Count} regions requested",
request.Id, allPoints.Count);
}
_logger.LogInformation("Route {RouteId} created successfully", request.Id);
return new RouteResponse
@@ -153,6 +181,11 @@ public class RouteService : IRouteService
TotalDistanceMeters = routeEntity.TotalDistanceMeters,
TotalPoints = routeEntity.TotalPoints,
Points = allPoints,
RequestMaps = routeEntity.RequestMaps,
MapsReady = routeEntity.MapsReady,
CsvFilePath = routeEntity.CsvFilePath,
SummaryFilePath = routeEntity.SummaryFilePath,
StitchedImagePath = routeEntity.StitchedImagePath,
CreatedAt = routeEntity.CreatedAt,
UpdatedAt = routeEntity.UpdatedAt
};
@@ -186,6 +219,11 @@ public class RouteService : IRouteService
SegmentIndex = p.SegmentIndex,
DistanceFromPrevious = p.DistanceFromPrevious
}).ToList(),
RequestMaps = route.RequestMaps,
MapsReady = route.MapsReady,
CsvFilePath = route.CsvFilePath,
SummaryFilePath = route.SummaryFilePath,
StitchedImagePath = route.StitchedImagePath,
CreatedAt = route.CreatedAt,
UpdatedAt = route.UpdatedAt
};