1 | <?php |
||
17 | class GeoTIFFReader extends AbstractResourceReader |
||
18 | { |
||
19 | /** |
||
20 | * The number of bytes required to hold a TIFF offset address. |
||
21 | * @var int |
||
22 | */ |
||
23 | const LEN_OFFSET = 4; |
||
24 | |||
25 | /** |
||
26 | * The number of bytes containing each item of elevation data |
||
27 | * (= BitsPerSample tag value / 8). |
||
28 | * @var int |
||
29 | */ |
||
30 | const BYTES_PER_SAMPLE = 2; |
||
31 | |||
32 | /** |
||
33 | * Magic number located at bytes 2-3 which identifies a TIFF file. |
||
34 | * @var int |
||
35 | */ |
||
36 | const MAGIC_TIFF_ID = 42; |
||
37 | |||
38 | /** @var int */ |
||
39 | const TIFF_CONST_STRIPOFSETS = 273; |
||
40 | |||
41 | /** @var int */ |
||
42 | const TIFF_CONST_IMAGE_WIDTH = 256; |
||
43 | |||
44 | /** @var int */ |
||
45 | const TIFF_CONST_IMAGE_LENGTH = 257; |
||
46 | |||
47 | /** @var int */ |
||
48 | const TIFF_CONST_STRIPBYTECOUNTS = 279; |
||
49 | |||
50 | /** @var int */ |
||
51 | const TIFF_CONST_IFD_ENTRY_BYTES = 12; |
||
52 | |||
53 | /** @var string */ |
||
54 | const BIG_ENDIAN = 'MM'; |
||
55 | |||
56 | /** @var string */ |
||
57 | const LITTLE_ENDIAN = 'II'; |
||
58 | |||
59 | /** @var int */ |
||
60 | const UNKNOWN = -32768; |
||
61 | |||
62 | /** @var int */ |
||
63 | protected $NumDataRows; |
||
64 | |||
65 | /** @var int */ |
||
66 | protected $NumDataCols; |
||
67 | |||
68 | /** @var int */ |
||
69 | protected $StripOffsets; |
||
70 | |||
71 | /** @var string */ |
||
72 | protected $ByteOrder; |
||
73 | |||
74 | 7 | public function readHeader() |
|
80 | |||
81 | /** |
||
82 | * Go to the file header and work out the byte order (bytes 0-1) and TIFF identifier (bytes 2-3). |
||
83 | * @throws RuntimeException |
||
84 | */ |
||
85 | 7 | protected function checkByteOrderAndTiffIdentifier() |
|
100 | |||
101 | /** |
||
102 | * The remaining 4 bytes in the header are the offset to the IFD. |
||
103 | */ |
||
104 | 7 | protected function goToIFDEntries() |
|
113 | |||
114 | /** |
||
115 | * Read IFD entries which (the number of entries in each is in the first two bytes). |
||
116 | */ |
||
117 | 7 | protected function readIFDEntries() |
|
139 | |||
140 | /** |
||
141 | * @return bool |
||
142 | */ |
||
143 | 7 | protected function isLittleEndian() |
|
147 | |||
148 | /** |
||
149 | * @param float $relativeLatitude |
||
150 | * @param float $relativeLongitude |
||
151 | * @return float[] array(row, col) |
||
152 | */ |
||
153 | 7 | public function getExactRowAndColFor($relativeLatitude, $relativeLongitude) |
|
160 | |||
161 | /** |
||
162 | * @param int $row |
||
163 | * @param int $col |
||
164 | * @return int|bool |
||
165 | */ |
||
166 | 7 | public function getElevationFor($row, $col) |
|
178 | } |
||
179 |