Skip to content

Commit de85ae9

Browse files
committed
Enhance logging when stops missing latitude and longitude when generating routes geojson file
1 parent 71dc5fb commit de85ae9

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

functions-python/pmtiles_builder/src/gtfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def stop_txt_is_lat_log_required(stop_row):
1616
Returns:
1717
bool: True if both latitude and longitude is required, False otherwise.
1818
"""
19-
location_type = get_safe_value(stop_row, "location_type", 0)
19+
location_type = get_safe_value(stop_row, "location_type", "0")
2020
return location_type in ("0", "1", "2")

functions-python/pmtiles_builder/src/gtfs_stops_to_geojson.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from collections import defaultdict
55

66
from csv_cache import CsvCache, ROUTES_FILE, TRIPS_FILE, STOP_TIMES_FILE, STOPS_FILE
7+
from gtfs import stop_txt_is_lat_log_required
78
from shared.helpers.runtime_metrics import track_metrics
9+
from shared.helpers.transform import get_safe_float
810

911
logger = logging.getLogger(__name__)
1012

@@ -60,10 +62,13 @@ def convert_stops_to_geojson(csv_cache: CsvCache, output_file):
6062
if (
6163
"stop_lat" not in row
6264
or "stop_lon" not in row
63-
or not row["stop_lat"]
64-
or not row["stop_lon"]
65+
or get_safe_float(row, "stop_lat") is None
66+
or get_safe_float(row, "stop_lon") is None
6567
):
66-
logger.warning(f"Missing coordinates for stop_id {stop_id}, skipping.")
68+
if stop_txt_is_lat_log_required(row):
69+
logger.warning(
70+
"Missing coordinates for stop_id {%s}, skipping.", stop_id
71+
)
6772
continue
6873

6974
# Routes serving this stop

functions-python/pmtiles_builder/tests/test_gtfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def test_not_required_cases(self):
1616
self.assertFalse(stop_txt_is_lat_log_required({"location_type": 4}))
1717

1818
def test_missing_location_type(self):
19-
self.assertFalse(stop_txt_is_lat_log_required({}))
20-
self.assertFalse(stop_txt_is_lat_log_required({"other": "value"}))
19+
self.assertTrue(stop_txt_is_lat_log_required({}))
20+
self.assertTrue(stop_txt_is_lat_log_required({"other": "value"}))

functions-python/pmtiles_builder/tests/test_gtfs_stops_to_geojson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_convert_stops_to_geojson(self):
5050
with open(output_file) as f:
5151
geojson = json.load(f)
5252
self.assertEqual(geojson["type"], "FeatureCollection")
53-
self.assertEqual(len(geojson["features"]), 2) # skips stop with no coords
53+
self.assertEqual(2, len(geojson["features"])) # skips stop with no coords
5454
props = geojson["features"][0]["properties"]
5555
self.assertIn("stop_id", props)
5656
self.assertIn("route_ids", props)

0 commit comments

Comments
 (0)