gistools/readers/gtfs/realtime/position.rs
1use pbf::{ProtoRead, Protobuf};
2
3/// A Position is a point on the Earth's surface.
4#[derive(Debug, Default, Clone, PartialEq)]
5pub struct GTFSRealtimePosition {
6 /// Degrees North, in the WGS-84 coordinate system.
7 pub latitude: f32, // 1 [float]
8 /// Degrees East, in the WGS-84 coordinate system.
9 pub longitude: f32, // 2 [float]
10 /// Bearing, in degrees, clockwise from North, i.e., 0 is North and 90 is East.
11 /// This can be the compass bearing, or the direction towards the next stop
12 /// or intermediate location.
13 /// This should not be direction deduced from the sequence of previous
14 /// positions, which can be computed from previous data.
15 pub bearing: Option<f32>, // 3 [float]
16 /// Odometer value, in meters.
17 pub odometer: Option<f64>, // 4 [double]
18 /// Momentary speed measured by the vehicle, in meters per second.
19 pub speed: Option<f32>, // 5 [float]
20}
21/// Read in the contents of the GTFSRealtimePosition
22impl ProtoRead for GTFSRealtimePosition {
23 fn read(&mut self, tag: u64, pb: &mut Protobuf) {
24 match tag {
25 1 => self.latitude = pb.read_fixed(),
26 2 => self.longitude = pb.read_fixed(),
27 3 => self.bearing = Some(pb.read_fixed()),
28 4 => self.odometer = Some(pb.read_fixed()),
29 5 => self.speed = Some(pb.read_fixed()),
30 _ => panic!("unknown tag {}", tag),
31 }
32 }
33}