Skip to content

Commit ed5a867

Browse files
authored
Made sure stops with missing coordinates are not written to stops-output.geojson (#1447)
1 parent 115ba31 commit ed5a867

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

functions-python/pmtiles_builder/src/stops_processor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ def add_to_stop_to_coordinates(
117117
if stop_lon is None or stop_lat is None:
118118
if is_lat_lon_required(location_type):
119119
self.logger.warning("Missing stop latitude and longitude : %s", row)
120-
else:
121-
self.logger.debug(
122-
"Missing optional stop latitude and longitude : %s", row
123-
)
124120
return
125121
self.stop_to_coordinates[stop_id] = (stop_lon, stop_lat)
126122

@@ -135,15 +131,16 @@ def add_to_stops_geojson(
135131
stop_url: str = "",
136132
wheelchair_boarding: str = "",
137133
location_type: str = "",
138-
stop_lon: float = 0.0,
139-
stop_lat: float = 0.0,
134+
stop_lon: float = None,
135+
stop_lat: float = None,
140136
) -> None:
141137
if stop_lon is None or stop_lat is None:
142138
if is_lat_lon_required(location_type):
143139
self.logger.warning(
144140
"Missing coordinates for stop_id {%s}, skipping.", stop_id
145141
)
146-
return
142+
# No point in writing a stop-feature if there are missing coordinates.
143+
return
147144

148145
route_ids = sorted(self.stop_times_processor.stop_to_routes.get(stop_id, []))
149146
route_colors = [

functions-python/pmtiles_builder/tests/test_stops_processor.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ def test_missing_coords_are_skipped(self):
7979
stops_path = csv_cache.get_path("stops.txt")
8080

8181
with open(stops_path, "w", encoding="utf-8") as f:
82-
f.write("stop_id,stop_lon,stop_lat,stop_name\n")
83-
# stop without coordinates
84-
f.write("stop_missing,,,NoCoords\n")
85-
f.write("stop_ok,-73.2,45.2,OK\n")
82+
f.write("stop_id,stop_lon,stop_lat,stop_name,location_type\n")
83+
# two stops without coordinates: one optional (3), one required (1)
84+
f.write("stop_missing_type3,,,Node,3\n")
85+
f.write("stop_missing_type1,,,Station,1\n")
86+
f.write("stop_ok,-73.2,45.2,OK,0\n")
8687

8788
routes_colors = DummyRoutesProcessorForColors({"r1": "FF0000"})
8889
stop_times = DummyStopTimesProcessor(
89-
{"stop_missing": {"r1"}, "stop_ok": {"r1"}}
90+
{
91+
"stop_missing_type3": {"r1"},
92+
"stop_missing_type1": {"r1"},
93+
"stop_ok": {"r1"},
94+
}
9095
)
9196

9297
processor = StopsProcessor(
@@ -108,7 +113,8 @@ def test_missing_coords_are_skipped(self):
108113
# only stop_ok should be present
109114
ids = [f.get("properties", {}).get("stop_id") for f in features]
110115
self.assertIn("stop_ok", ids)
111-
self.assertNotIn("stop_missing", ids)
116+
self.assertNotIn("stop_missing_type3", ids)
117+
self.assertNotIn("stop_missing_type1", ids)
112118

113119

114120
if __name__ == "__main__":

0 commit comments

Comments
 (0)