1 | <?php |
||
20 | class GeoTIFFReader extends AbstractResourceReader |
||
21 | { |
||
22 | /** |
||
23 | * The number of bytes required to hold a TIFF offset address. |
||
24 | * @var int |
||
25 | */ |
||
26 | const LEN_OFFSET = 4; |
||
27 | |||
28 | /** |
||
29 | * Magic number located at bytes 2-3 which identifies a TIFF file. |
||
30 | * @var int |
||
31 | */ |
||
32 | const MAGIC_TIFF_ID = 42; |
||
33 | |||
34 | /** @var int */ |
||
35 | const TIFF_CONST_STRIPOFSETS = 273; |
||
36 | |||
37 | /** @var int */ |
||
38 | const TIFF_CONST_IMAGE_WIDTH = 256; |
||
39 | |||
40 | /** @var int */ |
||
41 | const TIFF_CONST_IMAGE_LENGTH = 257; |
||
42 | |||
43 | /** @var int */ |
||
44 | const TIFF_CONST_BITS_PER_SAMPLE = 258; |
||
45 | |||
46 | /** @var int */ |
||
47 | const TIFF_CONST_SAMPLES_PER_PIXEL = 277; |
||
48 | |||
49 | /** @var int */ |
||
50 | const TIFF_CONST_ROWS_PER_STRIP = 278; |
||
51 | |||
52 | /** @var int */ |
||
53 | const TIFF_CONST_STRIPBYTECOUNTS = 279; |
||
54 | |||
55 | /** @var int */ |
||
56 | const TIFF_CONST_IFD_ENTRY_BYTES = 12; |
||
57 | |||
58 | /** @var string */ |
||
59 | const BIG_ENDIAN = 'MM'; |
||
60 | |||
61 | /** @var string */ |
||
62 | const LITTLE_ENDIAN = 'II'; |
||
63 | |||
64 | /** @var int */ |
||
65 | const UNKNOWN = -32768; |
||
66 | |||
67 | /** @var int The number of bytes containing each item of elevation data */ |
||
68 | protected $BytesPerSample = 2; |
||
69 | |||
70 | /** @var int The number of components per pixel */ |
||
71 | protected $SamplesPerPixel = 1; |
||
72 | |||
73 | /** @var int The number of rows per strip */ |
||
74 | protected $RowsPerStrip = 1; |
||
75 | |||
76 | /** @var int */ |
||
77 | protected $NumDataRows; |
||
78 | |||
79 | /** @var int */ |
||
80 | protected $NumDataCols; |
||
81 | |||
82 | /** @var int */ |
||
83 | protected $StripOffsets; |
||
84 | |||
85 | /** @var string */ |
||
86 | protected $ByteOrder; |
||
87 | |||
88 | public function readHeader() |
||
94 | |||
95 | /** |
||
96 | * Go to the file header and work out the byte order (bytes 0-1) and TIFF identifier (bytes 2-3). |
||
97 | * @throws RuntimeException |
||
98 | */ |
||
99 | protected function checkByteOrderAndTiffIdentifier() |
||
114 | |||
115 | /** |
||
116 | * The remaining 4 bytes in the header are the offset to the IFD. |
||
117 | */ |
||
118 | protected function goToIFDEntries() |
||
127 | |||
128 | /** |
||
129 | * Read IFD entries which (the number of entries in each is in the first two bytes). |
||
130 | */ |
||
131 | protected function readIFDEntries() |
||
162 | |||
163 | /** |
||
164 | * @return bool |
||
165 | */ |
||
166 | protected function isLittleEndian() |
||
170 | |||
171 | /** |
||
172 | * @param float $relativeLatitude |
||
173 | * @param float $relativeLongitude |
||
174 | * @return float[] array(row, col) |
||
175 | */ |
||
176 | public function getExactRowAndColFor($relativeLatitude, $relativeLongitude) |
||
183 | |||
184 | /** |
||
185 | * @param int $row |
||
186 | * @param int $col |
||
187 | * @return int|bool |
||
188 | */ |
||
189 | public function getElevationFor($row, $col) |
||
201 | } |
||
202 |