The final result is on http://cheow-thianliang.github.io/airports.html
The following are screenshots of Worldwide Airport Distribution
![]() |
Worldwide Airport Distribution |
![]() |
Show case the feature of hiding unwanted category of airport and display of airport name when mouse over |
These are the steps taken to map the worldwide airport distribution:
- Read and understand Let's Make a Map tutorial by Mike Bostock.
- Download airports.csv from OurAirports.com
- Create GeoJSON file for world map (Generate subunits.json as shown by Mike without the where clause)
- Convert airports.csv into GeoJSON using Python scriptThis file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import json import csv BALOONPORT = 'baloonport' CLOSED = 'closed' HELIPORT = 'heliport' LARGE_AIRPORT = 'large_airport' MEDIUM_AIRPORT = 'medium_airport' SEAPLANE_BASE = 'seaplane_base' SMALL_AIRPORT = 'small_airport' def create_airports_geo_json(file_path, category=LARGE_AIRPORT): features = [] with open(file_path) as csvfile: reader = csv.DictReader(csvfile) for row in reader: latitude = float(row['latitude_deg']) longitude = float(row['longitude_deg']) if row['type'] == category: feature = { 'geometry': { 'type': 'Point', 'coordinates': [longitude, latitude] }, 'type': 'Feature', 'properties': { 'NAME': row['name'], } } features.append(feature) data = { 'type': 'FeatureCollection', 'features': features } with open('%s.json' % category, 'w') as json_file: json.dump(data, json_file) - Merge and convert those GeoJSON file created in step 3 and 4 into topojson (Refer to Mike's blog)
- Create airports.html with Javascript code to render the result in 5.
References:
- Let's Make a Map tutorial by Mike Bostock
http://bost.ocks.org/mike/map/ - Airport data
http://ourairports.com/data/ - GeoJSON specification
http://geojson.org/geojson-spec.html - Using d3-tip to add tooltips by Caged
http://bl.ocks.org/Caged/6476579
No comments:
Post a Comment