forked from edarc/nexrad-l2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile.php
61 lines (55 loc) · 1.7 KB
/
tile.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
<?php
$GENERATOR_PROG = "/home/kyle/nexrad-processor/bin/gcc-4.3.2/release/gen-one";
$TILE_PREFIX = "/var/www/vhosts/neowx.com/httpdocs/radar/tiles";
$BASE_PREFIX = "/home/kyle/nexrad-processor/basefiles";
$site = $_GET['site'];
$t_x = $_GET['x'];
$t_y = $_GET['y'];
$t_z = $_GET['z'];
$base_file = "${BASE_PREFIX}/${site}.base";
$tile_file = "${TILE_PREFIX}/${site}_${t_z}_${t_x}-${t_y}.png";
if (!is_numeric($t_x) || !is_numeric($t_y) || !is_numeric($t_z)
|| !ereg('^K[A-Z]{3}$', $site))
{
// The input parameters are bogus.
header("HTTP/1.1 400 Bad Request");
exit;
}
clearstatcache();
if (file_exists($tile_file)
&& (filemtime($tile_file) > filemtime($base_file)))
{
// We generated this tile already and it's still up-to-date
header("X-Sendfile: ${tile_file}");
header("Content-Type: image/png");
header("X-NeoWX-Radar: cached");
}
else
{
// Invoke the tile generator to generate this tile
exec("${GENERATOR_PROG} ${base_file} ${t_x} ${t_y} ${t_z} ${tile_file}",
$output_arr);
$output = join("", $output_arr);
if ($output == "200")
{
// If it prints the string "200", the tile is in the coverage area and
// was generated.
header("X-Sendfile: ${tile_file}");
header("Content-Type: image/png");
header("X-NeoWX-Radar: generated");
}
else if ($output == "404")
{
// If it prints the string "404", the tile is outside the radar's
// coverage area and nothing was generated, so we 404.
header("HTTP/1.1 404 Not Found");
header("X-NeoWX-Radar: no-coverage");
}
else
{
// Something weird happened
header("HTTP/1.1 500 Internal Server Error");
echo $output;
}
}
?>