52 lines
1.7 KiB
Python
Executable file
52 lines
1.7 KiB
Python
Executable file
#!/usr/bin/env python
|
|
import csv
|
|
import io
|
|
import json
|
|
import urllib.request
|
|
|
|
index_imports = []
|
|
|
|
resp = urllib.request.urlopen("https://davidmegginson.github.io/ourairports-data/airports.csv")
|
|
airports = list(csv.DictReader(io.TextIOWrapper(resp)))
|
|
types = set([a['type'] for a in airports])
|
|
|
|
for airport_type in types:
|
|
|
|
geojson = {
|
|
"type": "FeatureCollection",
|
|
"features": [],
|
|
}
|
|
|
|
for airport in airports:
|
|
if airport['type'] == airport_type:
|
|
f = {
|
|
"type": "Feature",
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [float(airport['longitude_deg']), float(airport['latitude_deg'])]
|
|
},
|
|
"properties": {
|
|
"ID": airport['ident'],
|
|
"Name": airport['name'],
|
|
"City": airport['municipality'],
|
|
"Country": airport['iso_country'],
|
|
"Region": airport['iso_region'],
|
|
"Elevation (ft)": airport['elevation_ft'],
|
|
}
|
|
}
|
|
if airport['wikipedia_link']:
|
|
f['properties']['Wikipedia'] = airport['wikipedia_link']
|
|
if airport['home_link']:
|
|
f['properties']['Website'] = airport['home_link']
|
|
geojson['features'].append(f)
|
|
|
|
with open(f'data/{airport_type}.geojson', 'w') as f:
|
|
f.write(json.dumps(geojson))
|
|
|
|
with open("data/types.js", 'w') as f:
|
|
for airport_type in types:
|
|
f.write(f"import {airport_type} from './{airport_type}.geojson?url';\n")
|
|
f.write('\nexport default {\n')
|
|
for airport_type in types:
|
|
f.write(f" {airport_type}: {airport_type},\n")
|
|
f.write("};\n")
|