-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadDataToSQLXandYOptimized.php
94 lines (53 loc) · 1.98 KB
/
LoadDataToSQLXandYOptimized.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
try
{
$conn = new PDO("sqlsrv:Server=DESKTOP-BLQ3M1P\SQLEXPRESS;Database=Limburg02");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die (print_r($e->getMessage()));
}
//$counter = 0;
$log_directory = "tiles";
foreach(glob($log_directory.'/*') as $file) {
print("we have a file: ");
print("http://127.0.0.1/test/".$file);
$string = file_get_contents("http://127.0.0.1/test/".$file);
$json_a = json_decode($string, true);
$coord = "_x".$json_a['X']."_y".$json_a['Y'];
$tsql = "CREATE TABLE [".$coord."]([x] [int], [y] [int], [height] [float] NULL) ON [PRIMARY]";
$runSQLCreateTable = $conn->prepare($tsql);
$runSQLCreateTable->execute();
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($string, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
$localY = 0;
$localX = 0;
$globalX = 0;
$values = '';
foreach ($jsonIterator as $key => $val) {
if(!is_array($val) && is_float($val)) {
$localX = $globalX - ($localY * 2049);
//$parsedval = number_format((float)$val, 2, '.', '');
$parsedval = $val;
//$query = "INSERT [".$coord."] ([x], [y], [height]) VALUES (".$localX.", ".$localY.", ".$parsedval.")";
$values .= "('{$localX}', '{$localY}', '{$parsedval}'),";
$globalX++;
if($localX % 512 == 0 && $localX != 0) {
$values = rtrim($values, ',');
$query = "INSERT [Limburg02].[dbo].[".$coord."] ([x], [y], [height]) VALUES {$values} ;";
$runSQLAddData = $conn->prepare($query);
$runSQLAddData->execute();
//print("{$query} <br>");
$values = '';
}
} else if(is_array($val) && $key != 0) {
$localY++;
print("Y: ".$localY.", ");
}
}
}
//echo "number of numbers: $counter";
//echo $query;
?>