gistools/readers/gtfs/realtime/
shape.rs

1#![cfg_attr(feature = "nightly", coverage(off))]
2// NOTE: THis is an experimental module, exists incase the GTFS-Realtime spec changes to include it
3
4use alloc::string::String;
5use pbf::{ProtoRead, Protobuf};
6
7/// Describes the physical path that a vehicle takes when it's not part of the (CSV) GTFS,
8/// such as for a detour. Shapes belong to Trips, and consist of a sequence of shape points.
9/// Tracing the points in order provides the path of the vehicle.  Shapes do not need to intercept
10/// the location of Stops exactly, but all Stops on a trip should lie within a small distance of
11/// the shape for that trip, i.e. close to straight line segments connecting the shape points
12/// NOTE: This message is still experimental, and subject to change. It may be formally adopted in the future
13#[derive(Debug, Default, Clone, PartialEq)]
14pub struct GTFSRealtimeShape {
15    /// Identifier of the shape. Must be different than any shape_id defined in the (CSV) GTFS.
16    /// This field is required as per reference.md, but needs to be specified here optional because "Required is Forever"
17    /// See <https://developers.google.com/protocol-buffers/docs/proto#specifying_field_rules>
18    /// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
19    pub shape_id: Option<String>, // 1 [string]
20    /// Encoded polyline representation of the shape. This polyline must contain at least two points.
21    /// For more information about encoded polylines, see <https://developers.google.com/maps/documentation/utilities/polylinealgorithm>
22    /// This field is required as per reference.md, but needs to be specified here optional because "Required is Forever"
23    /// See <https://developers.google.com/protocol-buffers/docs/proto#specifying_field_rules>
24    /// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
25    pub encoded_polyline: Option<String>, // 2 [string]
26}
27/// Read in the contents of the GTFSRealtimeShape
28impl ProtoRead for GTFSRealtimeShape {
29    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
30        match tag {
31            1 => self.shape_id = Some(pb.read_string()),
32            2 => self.encoded_polyline = Some(pb.read_string()),
33            _ => panic!("unknown tag {}", tag),
34        }
35    }
36}