-
Notifications
You must be signed in to change notification settings - Fork 89
/
add_quadkeys.php
executable file
·59 lines (54 loc) · 1.35 KB
/
add_quadkeys.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
<?php
/**
3WiFi Script for add `quadkey` column to geo tables
**/
set_time_limit(0);
include 'config.php';
require 'db.php';
require 'quadkey.php';
db_connect();
foreach (array('geo', 'mem_geo') as $geo_table)
{
$sql = "ALTER TABLE `$geo_table`
ADD COLUMN `quadkey` BIGINT(20) UNSIGNED DEFAULT NULL,
DROP INDEX `Coords`,
ADD INDEX (`quadkey`)";
var_dump($sql);
if (!$db->query($sql))
{
echo "Failed to alter table $geo_table: ";
echo "(" . $db->errno . ") " . $db->error;
}
$coord_res = QuerySql(
"SELECT * FROM $geo_table
WHERE `latitude` != 0 AND `longitude` != 0
AND `latitude` IS NOT NULL AND `longitude` IS NOT NULL
AND `quadkey` IS NULL");
if (!$coord_res)
{
echo "Failed to select from $geo_table: ";
echo "(" . $db->errno . ") " . $db->error;
exit();
}
if (!($stmt = $db->prepare("UPDATE $geo_table SET `quadkey`=? WHERE `BSSID`=?")))
{
echo "Failed to prepare query: (" . $db->errno . ") " . $db->error;
exit();
}
$quadkey = '';
$bssid = '';
if (!$stmt->bind_param("ss", $quadkey, $bssid))
{
echo "Failed to bind params: (" . $stmt->errno . ") " . $stmt->error;
exit();
}
while ($coord_row = $coord_res->fetch_row()) {
$bssid = $coord_row[0];
$quadkey = base_convert(
latlon_to_quadkey($coord_row[1], $coord_row[2], MAX_ZOOM_LEVEL),
2,
10);
$stmt->execute();
}
$stmt->close();
}