transitland / transitland-processing-animation

Animating scheduled transit trips using the Transitland API and Processing
MIT License
279 stars 55 forks source link

Data feeds containing stops without any coordinates fail for the entire feed #4

Closed amcewen closed 6 years ago

amcewen commented 7 years ago

Running transitflow for the operator Cumfybus, i.e. python transitflow.py --name=cumfybus --operator=o-gcw0-cumfybus --recording, currently fails after downloading the data.

Digging into it, it seems to be because the origin_stops from the dataset includes a stop (s-gcw0vhqpk4-blackrodchurchst~redlionstopc) that isn't in the lats/lons, which causes python to throw an exception.

I've worked round it (because claiming the stop is in the mid-Atlantic, while hopefully quite obvious to see, doesn't seem the correct fix :-) with the following mod to transitflow.py:

 def generate_output(operator_onestop_id, origin_datetimes, destination_datetimes, durations, origin_stops, destination_stops, route_ids, lookup_stop_lats, lookup_stop_lons, lookup_vehicle_types):
     """This function generates the output table, to be saved later as a csv."""
-    origin_stop_lats = [lookup_stop_lats[i] for i in origin_stops]
-    origin_stop_lons = [lookup_stop_lons[i] for i in origin_stops]
-    destination_stop_lats = [lookup_stop_lats[i] for i in destination_stops]
-    destination_stop_lons = [lookup_stop_lons[i] for i in destination_stops]
+    origin_stop_lats = []
+    origin_stop_lons = []
+    for i in origin_stops:
+        try:
+            origin_stop_lats.append(lookup_stop_lats[i])
+            origin_stop_lons.append(lookup_stop_lons[i])
+        except:
+            origin_stop_lats.append(-3.094025)
+            origin_stop_lons.append(53.460255)
+    destination_stop_lats = []
+    destination_stop_lons = []
+    for i in destination_stops:
+        try:
+            destination_stop_lats.append(lookup_stop_lats[i])
+            destination_stop_lons.append(lookup_stop_lons[i])
+        except:
+            destination_stop_lats.append(0)
+            destination_stop_lons.append(0)

Happy to submit it as a pull request, if that is a valid fix, mind you.

willgeary commented 6 years ago

Thank you, @amcewen ! I agree with your idea of ignoring instances where stop lat/lons are not found and implemented something similar. Obviously, a more thorough solution would be to investigate why these particular stops are missing lat/lons in the database. But I agree that a single stop missing should not throw an error for an entire operator.

Cumfybus now works for me:

python transitflow.py --name=cumfybus --operator=o-gcw0-cumfybus

Cumfybus