The world is in constant flux, domestic and international flights play a role in the fast paced travel that has become a normality.
This project was conducted with python script in Jupyter notebook, to map out the airports and routes on our planet.
PYTHON SCRIPT:
import pandas as pd ports = pd.read_csv(“pathtoports.csv”)
print(ports)
from shapely.geometry
import Point
import geopandas as gpd
port_geometry = [Point(xy) for xy in zip(ports[‘lon’], ports[‘lat’])]
port_geodata = gpd.GeoDataFrame(ports, crs=”EPSG:4326″, geometry=port_geometry)
import matplotlib.pyplot as plt fig, ax = plt.subplots()
port_geodata.plot(ax=ax)
plt.show()
import cartopy.crs as ccrs
fig, ax = plt.subplots(subplot_kw={‘projection’: ccrs.Robinson()},figsize=(100,30)) port_geodata.plot(ax=ax, transform=ccrs.PlateCarree()) plt.show() # In[6]: airports = pd.read_csv(“pathtoairports.csv”, delimiter=’,’, names=[‘id’, ‘name’, ‘city’, ‘country’, ‘iata’, ‘icao’, ‘lat’, ‘long’, ‘altitude’, ‘timezone’, ‘dst’, ‘tz’, ‘type’, ‘source’]) # In[7]: print(airports)
routes = pd.read_csv(“pathwaytoroutes”, delimiter=’,’, names=[‘airline’, ‘id’, ‘source_airport’, ‘source_airport_id’, ‘destination_airport’, ‘destination_airport_id’, ‘codeshare’, ‘stops’, ‘equitment’])
print(routes)
source_airports = airports[[‘name’, ‘iata’, ‘icao’, ‘lat’, ‘long’]] destination_airports = source_airports.copy() source_airports.columns = [str(col) + ‘_source’ for col in source_airports.columns] destination_airports.columns = [str(col) + ‘_destination’ for col in destination_airports.columns]
routes = routes[[‘source_airport’, ‘destination_airport’]] routes = pd.merge(routes, source_airports, left_on=’source_airport’, right_on=’iata_source’) routes = pd.merge(routes, destination_airports, left_on=’destination_airport’, right_on=’iata_destination’) print(routes.columns)
from shapely.geometry import LineString routes_geometry = [LineString([[routes.iloc[i][‘long_source’], routes.iloc[i][‘lat_source’]], [routes.iloc[i][‘long_destination’], routes.iloc[i][‘lat_destination’]]]) for i in range(routes.shape[0])] routes_geodata = gpd.GeoDataFrame(routes, geometry=routes_geometry, crs=’EPSG:4326′)
print(routes.columns)
fig, ax = plt.subplots(figsize=(20,20)) ax.patch.set_facecolor(‘black’) routes_geodata.plot(ax=ax, color=’white’, linewidth=0.1) plt.show()
fig, ax = plt.subplots(subplot_kw={‘projection’: ccrs.Robinson()}, figsize=(20,20)) ax.patch.set_facecolor(‘black’) routes_geodata.plot(ax=ax, transform=ccrs.Geodetic(), color=’yellow’, linewidth=0.1, alpha=0.1) plt.setp(ax.spines.values(), color=’black’) plt.setp([ax.get_xticklines(), ax.get_yticklines()], color=’black’) ax.set_ylim(-7000000, 8800000) plt.show()