diff options
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs')
| -rw-r--r-- | src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs | 37 |
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) |
