-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpath.php
60 lines (53 loc) · 1.77 KB
/
path.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
<?php
error_reporting(-1);
if(isset($_GET["hour"])){
$hour = $_GET["hour"];
}
if(isset($_GET["min"])){
$min = $_GET["min"];
}
// Variables and constants
$file = "busroute.csv";
$row = 1;
$geo = array("type" => "FeatureCollection",
"features" => array(),
);
$preLat = 0;
$preLon = 0;
$preset = False;
// Parse the CSV file
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if($row != 1){
$time = date_parse($data[0]);
if(($time["hour"] === 0+$hour)&&($time["minute"] > $min) && ($time["minute"] < $min+30)){
// setting starting point
if(!$preset){
$preLat += $data[$num-2];
$preLon += $data[$num-1];
$preset = True;
}
else{
$lat = 0+$data[$num-2];
$lon = 0+$data[$num-1];
$feature = array("type" => "Feature",
"geometry" => array(
"type" => "LineString",
"coordinates" => array(array($preLon, $preLat),array($lon, $lat))
),
"properties" => array("speed" => 0+$data[1], "time" => $data[0])
);
array_push($geo["features"],$feature);
$preLat = $lat; // reassign lat,lon for next segment
$preLon = $lon;
}
}
}
$row++;
}
fclose($handle);
}
else die("error opening file");
echo(json_encode($geo));
?>