From a58f44d851c68869b1cdb28ff14119bfd1a8fc09 Mon Sep 17 00:00:00 2001 From: Bert Date: Tue, 7 Apr 2020 14:25:12 +0200 Subject: [PATCH] Fix crash in transfer validation when a stop has missing coordinates --- transitfeed/transfer.py | 9 +++++++-- transitfeed/util.py | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/transitfeed/transfer.py b/transitfeed/transfer.py index ddcd8b2e..01649da3 100755 --- a/transitfeed/transfer.py +++ b/transitfeed/transfer.py @@ -15,9 +15,10 @@ # limitations under the License. from __future__ import absolute_import -from .gtfsobjectbase import GtfsObjectBase from . import problems as problems_module from . import util +from .gtfsobjectbase import GtfsObjectBase + class Transfer(GtfsObjectBase): """Represents a transfer in a schedule""" @@ -154,12 +155,16 @@ def ValidateTransferWalkingTime(self, problems): return distance = self.GetTransferDistance() + if distance is None: + # If the distance cannot be determined because of missing coordinates on a stop, return + # The stops.txt validation will report the missing coordinates. + return # If min_transfer_time + 120s isn't enough for someone walking very fast # (2m/s) then issue a warning. # # Stops that are close together (less than 240m appart) never trigger this # warning, regardless of min_transfer_time. - FAST_WALKING_SPEED= 2 # 2m/s + FAST_WALKING_SPEED = 2 # 2m/s if self.min_transfer_time + 120 < distance / FAST_WALKING_SPEED: problems.TransferWalkingSpeedTooFast(from_stop_id=self.from_stop_id, to_stop_id=self.to_stop_id, diff --git a/transitfeed/util.py b/transitfeed/util.py index 1fea2dc8..d7246c6b 100644 --- a/transitfeed/util.py +++ b/transitfeed/util.py @@ -230,7 +230,7 @@ def _MaxVersion(versions): if len(versions) == 0: return None - version_tuple = lambda x: tuple(int(item) for item in x.split('.')) + version_tuple = lambda x: tuple(int(item) for item in x.split('.')) return max(versions, key=version_tuple) OUTPUT_ENCODING = 'utf-8' @@ -534,6 +534,8 @@ def ApproximateDistanceBetweenStops(stop1, stop2): Earth is a sphere.""" if (stop1.stop_lat is None or stop1.stop_lon is None or stop2.stop_lat is None or stop2.stop_lon is None): + print('Cannot determine distance between stops %s and %s due to missing coordinates' + % (stop1.stop_id, stop2.stop_id)) return None return ApproximateDistance(stop1.stop_lat, stop1.stop_lon, stop2.stop_lat, stop2.stop_lon)