Requires Python 3
NaPTAN data from http://naptan.app.dft.gov.uk/datarequest/help
Requires Python 3
NaPTAN data from http://naptan.app.dft.gov.uk/datarequest/help
.DEFAULT_GOAL := tiploc_locations.csv | |
naptan.zip: | |
wget -O naptan.zip naptan.app.dft.gov.uk/DataRequest/Naptan.ashx?format=csv | |
Stops.csv: naptan.zip | |
unzip -o naptan.zip | |
tiploc_locations.csv: Stops.csv | |
python run.py |
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: | |
try: | |
geo_stops.append([station[1], stops[station[0]][0], stops[station[0]][1]]) | |
except: | |
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: | |
writer.writerow(station) | |
# print(geo_stops) |