|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* phpMyAdmin ShapeFile library |
|
4
|
|
|
* <https://github.com/phpmyadmin/shapefile/> |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2006-2007 Ovidio <ovidio AT users.sourceforge.net> |
|
7
|
|
|
* Copyright 2016 Michal Čihař <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program; if not, you can download one from |
|
20
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
21
|
|
|
*/ |
|
22
|
|
|
namespace ShapeFile; |
|
23
|
|
|
|
|
24
|
|
|
class Util { |
|
25
|
|
|
private static $little_endian = null; |
|
26
|
|
|
|
|
27
|
|
|
public static function loadData($type, $data) { |
|
28
|
|
|
if (!$data) { |
|
29
|
|
|
return $data; |
|
30
|
|
|
} |
|
31
|
|
|
$tmp = unpack($type, $data); |
|
32
|
|
|
return current($tmp); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public static function swap($binValue) { |
|
36
|
|
|
$result = $binValue{strlen($binValue) - 1}; |
|
37
|
|
|
for ($i = strlen($binValue) - 2; $i >= 0; $i--) { |
|
38
|
|
|
$result .= $binValue{$i}; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return $result; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public static function packDouble($value) { |
|
45
|
|
|
$value = (double) $value; |
|
46
|
|
|
$bin = pack("d", $value); |
|
47
|
|
|
|
|
48
|
|
|
if (is_null(self::$little_endian)) { |
|
49
|
|
|
self::$little_endian = (pack('L', 1) == pack('V', 1)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if (self::$little_endian) { |
|
53
|
|
|
return $bin; |
|
54
|
|
|
} else { |
|
55
|
|
|
return self::swap($bin); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|