Fix transport POIs

This commit is contained in:
Andras Schmelczer 2026-04-04 09:49:06 +01:00
parent a26494b028
commit 23d128ff63

View file

@ -18,6 +18,7 @@ STOP_TYPES = {
"BCE": "Bus station",
"TXR": "Taxi rank",
"TMU": "Metro or Tram stop",
"MET": "Metro or Tram stop",
}
@ -44,9 +45,30 @@ def download_naptan(output: Path) -> None:
pl.col("StopType").replace(STOP_TYPES).alias("category"),
pl.col("Latitude").alias("lat"),
pl.col("Longitude").alias("lng"),
pl.col("NptgLocalityCode").alias("locality"),
)
)
before = len(df)
# Deduplicate: one record per name+category+locality
# (merges entrances, bus stop pairs on opposite sides of the road, etc.)
has_loc = df.filter(
pl.col("locality").is_not_null() & (pl.col("locality") != "")
)
no_loc = df.filter(
pl.col("locality").is_null() | (pl.col("locality") == "")
)
cols = ["id", "name", "category", "lat", "lng"]
deduped = has_loc.group_by("name", "category", "locality").agg(
pl.col("id").first(),
pl.col("lat").mean(),
pl.col("lng").mean(),
)
df = pl.concat([deduped.select(cols), no_loc.select(cols)])
print(f"Deduplicated {before:,}{len(df):,} stops (by name+category+locality)")
df.write_parquet(output)
size_mb = output.stat().st_size / (1024 * 1024)
print(f"Wrote {output} ({size_mb:.1f} MB, {len(df):,} stations)")