diff --git a/src/model.rs b/src/model.rs index 15aa838e2..276c9957e 100644 --- a/src/model.rs +++ b/src/model.rs @@ -276,7 +276,7 @@ impl Collections { let mut stop_area_ids_used: HashSet = HashSet::new(); let mut equipments_used: HashSet = HashSet::new(); - let stop_locations = self + let mut stop_locations = self .stop_locations .take() .into_iter() @@ -330,7 +330,7 @@ impl Collections { .collect::>(); self.pathways = CollectionWithId::new(pathways)?; - let stop_points = self + let mut stop_points = self .stop_points .take() .into_iter() @@ -395,7 +395,7 @@ impl Collections { }) .collect(), )?; - let stop_areas = self + let mut stop_areas = self .stop_areas .take() .into_iter() @@ -416,6 +416,33 @@ impl Collections { }) .collect::>(); + for sa in stop_areas.iter_mut().filter(|sa| !sa.coord.is_valid()) { + debug!( + "stop area {} geographic coordinates are not valid and set to (0, 0)", + sa.id + ); + sa.coord = Coord::default(); + } + + for sp in stop_points.iter_mut().filter(|sp| !sp.coord.is_valid()) { + debug!( + "stop point {} geographic coordinates are not valid and set to (0, 0)", + sp.id + ); + sp.coord = Coord::default(); + } + + for sl in stop_locations + .iter_mut() + .filter(|sl| sl.stop_type == StopType::StopEntrance && !sl.coord.is_valid()) + { + debug!( + "stop access {} geographic coordinates are not valid and set to (0, 0)", + sl.id + ); + sl.coord = Coord::default(); + } + comments_used.extend(self.stop_time_comments.iter().filter_map( |((vj_id, _), comment_id)| { if vjs_used.contains(vj_id.as_str()) { @@ -2221,4 +2248,35 @@ mod tests { assert_eq!(2, vj.stop_times.len()); } } + + mod check_coord_integrity { + use crate::objects::Coord; + + #[test] + fn check_valid_coord() { + let coord = Coord { + lon: 2.372987, + lat: 48.844746, + }; + assert!(coord.is_valid()); + } + } + + #[test] + fn check_unvalid_lon() { + let coord = Coord { + lon: -182., + lat: 48.844746, + }; + assert!(!coord.is_valid()); + } + + #[test] + fn check_unvalid_lat() { + let coord = Coord { + lon: 2.372987, + lat: 91., + }; + assert!(!coord.is_valid()); + } } diff --git a/src/objects.rs b/src/objects.rs index 6387e3c7a..9adad33ec 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -980,6 +980,10 @@ impl Coord { 2. * EARTH_RADIUS * f64::asin(f64::sqrt(x + y)) } + pub fn is_valid(&self) -> bool { + (self.lon >= -180. && self.lon <= 180.) && (self.lat >= -90. && self.lat <= 90.) + } + /// Returns a proxy object allowing to compute approximate /// distances for cheap computation. ///