-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurveyAnalysis_BusinessTravel_maps.py
246 lines (171 loc) · 9.07 KB
/
SurveyAnalysis_BusinessTravel_maps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
'''
Script to plot destinations of business travels on maps
'''
import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
from shapely.geometry import Point
from mpl_toolkits.basemap import Basemap
# Read the .csv files with destination coordinates
national_destinations = pd.read_csv('csv/national_destinations.csv')
international_destinations = pd.read_csv('csv/international_destinations.csv')
# Initialize the figure and basemap
fig, axs = plt.subplots(1, 2, figsize=(12, 8))
# Basemap of Denmark
lats_dk = [54.5, 58]
lons_dk = [8, 14]
m = Basemap(projection='merc', llcrnrlat=lats_dk[0], urcrnrlat=lats_dk[1], llcrnrlon=lons_dk[0], urcrnrlon=lons_dk[1], resolution='i', ax=axs[0])
m.drawmapboundary(fill_color='lightcyan')
m.fillcontinents(color='ForestGreen', lake_color='lightcyan', alpha=0.35)
m.drawcoastlines(linewidth=0.1)
m.drawcountries(linewidth=0.2)
plot_city_labels = ['København', 'Ølstykke', 'Helsingør', 'Sjællands Odde', 'Sorø', 'Køge',
'København', 'Odense', 'Nyborg', 'Svendborg', 'Fredericia', 'Vejle', 'Sønderborg',
'Esbjerg', 'Aarhus', 'Silkeborg', 'Herning', 'Viborg', 'Skive', 'Aalborg']
# Plot each city on the map
for index, row in national_destinations.iterrows():
x, y = m(row['Longitude'], row['Latitude'])
# Add city labels
if row['Destination'] in plot_city_labels:
m.plot(x, y, 'o', markersize=3, color='navy')
axs[0].text(x, y+3500, row['Destination'], fontsize=12, ha='center', va='bottom', color='navy')
else:
m.plot(x, y, 'o', markersize=2, color='navy', alpha=0.5)
axs[0].set_title('National Travel Destinations')
# Basemap of Sjælland
lats = [55.2, 56.15]
lons = [11.05, 12.7]
m2 = Basemap(projection='merc', llcrnrlat=lats[0], urcrnrlat=lats[1], llcrnrlon=lons[0], urcrnrlon=lons[1], resolution='i', ax=axs[1])
m2.drawmapboundary(fill_color='lightcyan')
m2.fillcontinents(color='ForestGreen', lake_color='lightcyan', alpha=0.35)
m2.drawcoastlines(linewidth=0.1)
m2.drawcountries(linewidth=0.2)
plot_city_labels = ['København', 'Roskilde', 'Helsingør', 'Sjællands Odde', 'Flakkebjerg', 'Slagelse',
'Korsør', 'Sorø', 'Køge', 'Hundested', 'Lejre', 'Hvalsø', 'Risø', 'DTU Lyngby',
'København', 'Taastrup', 'Greve', 'Ølstykke', 'Tårnby', 'Vedskølle']
# Plot each city (within Sjælland) on the map
for index, row in national_destinations.iterrows():
# Check if the city is located in Sjælland
if (lats[0] <= row['Latitude'] <= lats[1]) and (lons[0] <= row['Longitude'] <= lons[1]):
x2, y2 = m2(row['Longitude'], row['Latitude'])
if row['Destination'] in plot_city_labels:
m2.plot(x2, y2, 'o', markersize=3, color='navy')
axs[1].text(x2, y2+2000, row['Destination'], fontsize=12, ha='center', va='bottom', color='navy')
else:
m2.plot(x2, y2, 'o', markersize=2, color='navy', alpha=0.5)
axs[1].set_title('National Travel Destinations in Sjælland')
fig.tight_layout()
fig.savefig('Figures/national_destinations_map.png', dpi=300, bbox_inches='tight')
# International destinations (Europe) with Basemap
fig, ax = plt.subplots(1, figsize=(12, 8))
# Basemap of Europe
lats_eu = [35, 70]
lons_eu = [-10, 30]
m3 = Basemap(projection='merc', llcrnrlat=lats_eu[0], urcrnrlat=lats_eu[1], llcrnrlon=lons_eu[0], urcrnrlon=lons_eu[1], resolution='i', ax=ax)
m3.drawmapboundary(fill_color='lightcyan')
m3.fillcontinents(color='ForestGreen', lake_color='lightcyan', alpha=0.35)
m3.drawcoastlines(linewidth=0.1)
m3.drawcountries(linewidth=0.2)
plot_city_labels = ['København', 'Thorshavn', 'Ålesund', 'Oslo', 'Oulu', 'Umeå', 'Bergen', 'Stockholm',
'Helsinki', 'Edinburgh', 'Newcastle', 'Dublin', 'London', 'Hamburg', 'Berlin', 'Utrecht',
'Bruxelles', 'München', 'Paris', 'Wien', 'Geneva', 'Grenoble', 'Milan', 'Venedig',
'Toulouse', 'Spain', 'Faro', 'Innsbruck', 'Leipzig']
# Plot each city (within Sjælland) on the map
for index, row in international_destinations.iterrows():
# Check if the city is located in Sjælland
if (lats_eu[0] <= row['Latitude'] <= lats_eu[1]) and (lons_eu[0] <= row['Longitude'] <= lons_eu[1]):
x3, y3 = m3(row['Longitude'], row['Latitude'])
if row['Destination'] in plot_city_labels:
m3.plot(x3, y3, 'o', markersize=3, color='navy')
if row['Destination'] in ['Grenoble', 'Venedig', 'København', 'Stockholm', 'Innsbruck']:
ax.text(x3, y3-10000, row['Destination'], fontsize=12, ha='center', va='top', color='navy')
else:
ax.text(x3, y3+10000, row['Destination'], fontsize=12, ha='center', va='bottom', color='navy')
else:
m3.plot(x3, y3, 'o', markersize=2, color='navy', alpha=0.5)
ax.set_title('European travels')
fig.tight_layout()
fig.savefig('Figures/european_destinations_map.png', dpi=300, bbox_inches='tight')
# International destinations (World) with Basemap
fig, ax = plt.subplots(1, figsize=(12, 8))
# Basemap of the world
m4 = Basemap(projection='merc', llcrnrlat=-60, urcrnrlat=85, llcrnrlon=-180, urcrnrlon=180, resolution='i', ax=ax)
m4.drawmapboundary(fill_color='lightcyan')
m4.fillcontinents(color='ForestGreen', lake_color='lightcyan', alpha=0.35)
m4.drawcoastlines(linewidth=0.1)
m4.drawcountries(linewidth=0.2)
plot_city_labels = ['San Francisco', 'Banff', 'Athen', 'Florianopolis', 'Australien', 'Shanghai',
'Station Nord', 'Nuuk', 'Heraklion', 'Cyprus', 'Marrakesh', 'Faro', 'Berlin'
'Paris', 'Toulouse', 'København', 'Thorshavn', 'Oslo', 'Oulu', 'Edinburgh',
'Venedig', 'Longyearbyen']
# Plot each city (within Sjælland) on the map
for index, row in international_destinations.iterrows():
x4, y4 = m4(row['Longitude'], row['Latitude'])
print(row['Destination'])
if row['Destination'] in plot_city_labels:
m4.plot(x4, y4, 'o', markersize=3, color='navy')
if row['Destination'] in ['København', 'Venedig', 'Marrakesh', 'Faro']:
ax.text(x4, y4-50000, row['Destination'], fontsize=12, ha='center', va='top', color='navy')
else:
ax.text(x4, y4+50000, row['Destination'], fontsize=12, ha='center', va='bottom', color='navy')
else:
m4.plot(x4, y4, 'o', markersize=2, color='navy', alpha=0.5)
fig.tight_layout()
fig.savefig('Figures/worldwide_destinations_map.png', dpi=300, bbox_inches='tight')
plt.show()
# geometry_europe =[Point(lonlat) for lonlat in zip(international_destinations['Longitude'], international_destinations['Latitude'])]
# gdf_europe = gpd.GeoDataFrame(international_destinations, geometry=geometry_europe)
# # Create plot with world map
# fig, ax = plt.subplots(1, 1, figsize=(12, 8))
# world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
# world.boundary.plot(ax=ax, linewidth=1)
# # Define the region of Europe
# region_europe = gdf_europe.cx[-10:30, 35:70]
# # Omit Denmark from the European destinations
# region_europe = region_europe[region_europe['Destination'] != 'København']
# # Plot the European destinations
# region_europe.plot(ax=ax, color='red', markersize=20)
# for x, y, label in zip(region_europe.geometry.x, region_europe.geometry.y, region_europe['Destination']):
# ax.text(x, y, label, fontsize=8, ha='right')
# ax.set_title('International Travel Destinations in Europe')
# ax.set_xlabel('Longitude')
# ax.set_ylabel('Latitude')
# # Set the plot limits to focus on Europe
# ax.set_xlim(-10, 30)
# ax.set_ylim(35, 70)
# plt.show()
# # Setting the map type
# world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
# # Create a plot for national destinations
# lons_use = [8, 13]
# lats_use = [54.5, 58]
# fig, ax = plt.subplots(1, 1, figsize=(10, 10))
# world.boundary.plot(ax=ax, linewidth=1)
# # Set the plot limits to focus on Denmark
# ax.set_xlim(lons_use[0], lons_use[1])
# ax.set_ylim(lats_use[0], lats_use[1])
# # Set the title and labels
# ax.set_title('National Travel Destinations')
# ax.set_xlabel('Longitude')
# ax.set_ylabel('Latitude')
# plt.show()
# print(national_destinations)
# # Plot the destinations on maps, one for national and one for international travel
# def plot_travel_destinations(df, title, ax, world=gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))):
# '''
# Plot travel destinations on a map
# '''
# gdf = gpd.GeoDataFrame(df, geometry=[Point(lonlat) for lonlat in zip(df['Longitude'], df['Latitude'])])
# world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
# # Plotting
# world.plot(ax=ax, color='white', edgecolor='black')
# gdf.plot(ax=ax, color='red', markersize=20)
# for x, y, label in zip(gdf.geometry.x, gdf.geometry.y, gdf['Destination']):
# print(gdf['Destination'])
# ax.text(x, y, label, fontsize=8, ha='right')
# ax.set_title(title)
# ax.set_xlabel('Longitude')
# ax.set_ylabel('Latitude')
# # Plot national destinations on Denmark map
# fig, ax = plt.subplots(1, 1, figsize=(20, 10))
# plot_travel_destinations(national_destinations, 'National Travel Destinations', ax,)