-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtra.php
More file actions
43 lines (35 loc) · 987 Bytes
/
tra.php
File metadata and controls
43 lines (35 loc) · 987 Bytes
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
<?php
$lines = file('station.csv');
foreach ($lines as $line) {
$stations[] = str_getcsv($line);
}
// remove keys.
unset($stations[0]);
$geometry = [
'type' => 'Point'
];
foreach ($stations as $station) {
list($id, $timetable_id, $name, $branch, $address, $telephone, $lat, $lon) = $station;
$geometry['coordinates'] = [(float) $lon, (float) $lat];
$properties = [
'編號' => (string) $id,
'時刻表編號' => (string) $timetable_id,
'站名' => $name,
'支線' => $branch,
'地址' => $address,
'電話' => (string) $telephone,
'緯度' => (float) $lat,
'經度' => (float) $lon
];
$feature = [
'type' => 'Feature',
'geometry' => $geometry,
'properties' => $properties
];
$features[] = $feature;
}
$geojson = [
'type' => 'FeatureCollection',
'features' => $features
];
echo json_encode($geojson, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);