Skip to content

Instantly share code, notes, and snippets.

Last active Sep 30, 2019
What would you like to do?
Produce a CSV with Tiploc code, Longitude, and Latitude using Naptan data
.DEFAULT_GOAL := tiploc_locations.csv
wget -O
unzip -o
tiploc_locations.csv: Stops.csv
import csv
def load_rail_references():
stations = []
with open('RailReferences.csv', 'r') as csv_file:
reader = csv.DictReader(csv_file)
for line in reader:
stations.append([line['AtcoCode'], line['TiplocCode']])
return stations
def load_stops():
stops = {}
with open('Stops.csv', encoding='latin-1') as csv_file:
reader = csv.DictReader(csv_file)
for line in reader:
if line['StopType'] == 'RLY':
stops[line['ATCOCode']] = [line['Longitude'], line['Latitude']]
return stops
# print(load_rail_references())
# print(load_stops())
if __name__ == '__main__':
stations = load_rail_references()
stops = load_stops()
geo_stops = []
for station in stations:
geo_stops.append([station[1], stops[station[0]][0], stops[station[0]][1]])
print(f"{station[1]} not found")
with open('tiploc_locations.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['Tiploc', 'Longitude', 'Latitude'])
for station in geo_stops:
# print(geo_stops)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment