|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
|
|
3
|
|
|
import sys |
|
4
|
|
|
import os |
|
5
|
|
|
|
|
6
|
|
|
import numpy |
|
7
|
|
|
|
|
8
|
|
|
sys.path.append('../nsmaps') |
|
9
|
|
|
|
|
10
|
|
|
import nsmaps |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
DATA_DIR = './website/nsmaps-data' |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
def test(): |
|
17
|
|
|
stations = nsmaps.station.Stations(DATA_DIR) |
|
18
|
|
|
|
|
19
|
|
|
departure_station_name = 'Utrecht Centraal' |
|
20
|
|
|
departure_station = stations.find_station(departure_station_name) |
|
21
|
|
|
assert os.path.exists(os.path.join(DATA_DIR, 'contours/')) |
|
22
|
|
|
|
|
23
|
|
|
test_config = nsmaps.contourmap.ContourPlotConfig() |
|
24
|
|
|
# test_config = nsmaps.contourmap.TestConfig() |
|
25
|
|
|
test_config.print_bounding_box() |
|
26
|
|
|
|
|
27
|
|
|
create_contour_tiles_for_station(departure_station, stations, test_config) |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
def create_contour_tiles_for_station(departure_station, stations, config): |
|
31
|
|
|
max_zoom = 11 |
|
32
|
|
|
max_level = 180 |
|
33
|
|
|
filepaths = [] |
|
34
|
|
|
contourmap = nsmaps.contourmap.Contour(departure_station, stations, config, DATA_DIR) |
|
35
|
|
|
|
|
36
|
|
|
filepath_major = os.path.join(DATA_DIR, 'contours/' + departure_station.get_code() + '_major.geojson') |
|
37
|
|
|
if os.path.exists(filepath_major): |
|
38
|
|
|
print('WARNING: skipping station ' + departure_station.get_code() + ', files already exist.') |
|
39
|
|
|
return |
|
40
|
|
|
filepaths.append(filepath_major) |
|
41
|
|
|
contourmap.create_contour_data(filepath_major) |
|
42
|
|
|
levels = numpy.linspace(0, max_level, num=13) |
|
43
|
|
|
contourmap.create_geojson(filepath_major, min_zoom=0, max_zoom=max_zoom-2, stroke_width=8, levels=levels) |
|
44
|
|
|
|
|
45
|
|
|
filepath_minor = os.path.join(DATA_DIR, 'contours/' + departure_station.get_code() + '_minor.geojson') |
|
46
|
|
|
filepaths.append(filepath_minor) |
|
47
|
|
|
levels_minor = numpy.linspace(0, max_level, num=19) |
|
48
|
|
|
contourmap.create_geojson(filepath_minor, min_zoom=max_zoom-1, max_zoom=max_zoom, stroke_width=8, levels=levels_minor) |
|
49
|
|
|
|
|
50
|
|
|
filepath_top = os.path.join(DATA_DIR, 'contours/' + departure_station.get_code() + '_top.geojson') |
|
51
|
|
|
filepaths.append(filepath_top) |
|
52
|
|
|
levels_top = numpy.linspace(0, max_level, num=7) |
|
53
|
|
|
contourmap.create_geojson(filepath_top, min_zoom=0, max_zoom=max_zoom, stroke_width=16, levels=levels_top) |
|
54
|
|
|
|
|
55
|
|
|
tile_dir = os.path.join(DATA_DIR, 'contours/' + departure_station.get_code() + '/tiles/') |
|
56
|
|
|
contourmap.create_geojson_tiles(filepaths, tile_dir=tile_dir, min_zoom=0, max_zoom=max_zoom) |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
def create_all(): |
|
60
|
|
|
stations = nsmaps.station.Stations(DATA_DIR) |
|
61
|
|
|
|
|
62
|
|
|
# config = nsmaps.contourmap.TestConfig() |
|
63
|
|
|
config = nsmaps.contourmap.ContourPlotConfig() |
|
64
|
|
|
|
|
65
|
|
|
for departure_station in stations: |
|
66
|
|
|
if departure_station.has_travel_time_data(): |
|
67
|
|
|
# if departure_station.get_type() == 'megastation': |
|
68
|
|
|
create_contour_tiles_for_station(departure_station, stations, config) |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
if __name__ == "__main__": |
|
72
|
|
|
# test() |
|
73
|
|
|
create_all() |