aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-23 21:33:17 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-23 21:33:17 +0100
commit4a866f5352a51916ddb9849b2d68213856196c9c (patch)
tree3ba01ba01d5f6931adaf708b76ffccdd798fc78b /src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs
parent87417c313b455ba0dee19708528cc8d0b830a276 (diff)
Full real-time page, coruña real time
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs')
-rw-r--r--src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs b/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs
index 300ce70..93e4a4f 100644
--- a/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs
+++ b/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs
@@ -20,6 +20,9 @@ public class ShapeProcessor : IArrivalsProcessor
foreach (var arrival in context.Arrivals)
{
+ // If shape is already populated (e.g. by VitrasaRealTimeProcessor), skip
+ if (arrival.Shape != null) continue;
+
if (arrival.RawOtpTrip is not ArrivalsAtStopResponse.Arrival otpArrival) continue;
var encodedPoints = otpArrival.Trip.Geometry?.Points;
@@ -34,14 +37,46 @@ public class ShapeProcessor : IArrivalsProcessor
var points = Decode(encodedPoints);
if (points.Count == 0) continue;
- arrival.Shape = new
+ var features = new List<object>();
+
+ // Route LineString
+ features.Add(new
{
type = "Feature",
geometry = new
{
type = "LineString",
coordinates = points.Select(p => new[] { p.Lon, p.Lat }).ToList()
+ },
+ properties = new { type = "route" }
+ });
+
+ // Stops
+ if (otpArrival.Trip.Stoptimes != null)
+ {
+ foreach (var stoptime in otpArrival.Trip.Stoptimes)
+ {
+ features.Add(new
+ {
+ type = "Feature",
+ geometry = new
+ {
+ type = "Point",
+ coordinates = new[] { stoptime.Stop.Lon, stoptime.Stop.Lat }
+ },
+ properties = new
+ {
+ type = "stop",
+ name = stoptime.Stop.Name
+ }
+ });
}
+ }
+
+ arrival.Shape = new
+ {
+ type = "FeatureCollection",
+ features = features
};
}
catch (Exception ex)