-
Notifications
You must be signed in to change notification settings - Fork 23
/
northern-taiwan.php
72 lines (62 loc) · 1.68 KB
/
northern-taiwan.php
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
<?php
$area_name = 'northern-taiwan';
// use wikipedia colors
$colors = [
'BR' => '#c48c31',
'R' => '#e3002c',
'G' => '#008659',
'O' => '#f8b61c',
'BL' => '#0070bd',
'Y' => '#fddb00',
'A' => '#8246af',
];
$geometry = [
'type' => 'Point'
];
$lines = file($area_name . '.csv');
foreach ($lines as $line) {
$stations[] = str_getcsv($line);
}
// remove column name
unset($stations[0]);
foreach ($stations as $station) {
list(
$station_code,
/* $construction_id */,
$station_name_tw,
$station_name_en,
$line_code,
$line_name,
$address,
$lat,
$lon
) = $station;
$geometry['coordinates'] = [(float) $lon, (float) $lat];
$properties = [
'車站編號' => $station_code,
'中文站名' => $station_name_tw,
'英譯站名' => $station_name_en,
'路線編號' => $line_code,
'路線名' => $line_name,
'地址' => $address,
'緯度' => (float) $lat,
'經度' => (float) $lon,
// https://help.github.com/en/github/managing-files-in-a-repository/mapping-geojson-files-on-github#styling-features
'marker-size' => 'medium',
'marker-symbol' => 'rail-metro',
'marker-color' => $colors[$line_code],
];
$feature = [
'type' => 'Feature',
'geometry' => $geometry,
'properties' => $properties
];
$features[] = $feature;
}
$geojson = [
'type' => 'FeatureCollection',
'features' => $features
];
$handle = fopen($area_name . '.geojson', 'w+');
fwrite($handle, json_encode($geojson, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
fclose($handle);