@@ -5,14 +5,14 @@ |
||
5 | 5 | $shp->loadFromFile('data/mexico.*'); |
6 | 6 | |
7 | 7 | $i = 1; |
8 | -foreach($shp->records as $record){ |
|
8 | +foreach ($shp->records as $record) { |
|
9 | 9 | echo "<pre>"; |
10 | 10 | echo "Record No. $i:\n\n\n"; |
11 | 11 | echo "SHP Data = "; |
12 | - print_r($record->SHPData); //All the data related to the poligon |
|
12 | + print_r($record->SHPData); //All the data related to the poligon |
|
13 | 13 | print_r("\n\n\n"); |
14 | 14 | echo "DBF Data = "; |
15 | - print_r($record->DBFData); //All the information related to each poligon |
|
15 | + print_r($record->DBFData); //All the information related to each poligon |
|
16 | 16 | print_r("\n\n\n"); |
17 | 17 | echo "</pre>"; |
18 | 18 | $i++; |
@@ -5,14 +5,14 @@ |
||
5 | 5 | $shp->loadFromFile('data/capitals.*'); |
6 | 6 | |
7 | 7 | $i = 1; |
8 | -foreach($shp->records as $record){ |
|
8 | +foreach ($shp->records as $record) { |
|
9 | 9 | echo "<pre>"; |
10 | 10 | echo "Record No. $i:\n\n\n"; |
11 | 11 | echo "SHP Data = "; |
12 | - print_r($record->SHPData); //All the data related to the point |
|
12 | + print_r($record->SHPData); //All the data related to the point |
|
13 | 13 | print_r("\n\n\n"); |
14 | 14 | echo "DBF Data = "; |
15 | - print_r($record->DBFData); //All the information related to each point |
|
15 | + print_r($record->DBFData); //All the information related to each point |
|
16 | 16 | print_r("\n\n\n"); |
17 | 17 | echo "</pre>"; |
18 | 18 | $i++; |
@@ -17,9 +17,9 @@ |
||
17 | 17 | $shp->addRecord($record2); |
18 | 18 | |
19 | 19 | $shp->setDBFHeader(array( |
20 | - array('ID', 'N', 8, 0), |
|
21 | - array('DESC', 'C', 50, 0) |
|
22 | - )); |
|
20 | + array('ID', 'N', 8, 0), |
|
21 | + array('DESC', 'C', 50, 0) |
|
22 | + )); |
|
23 | 23 | |
24 | 24 | $shp->records[0]->DBFData['ID'] = '1'; |
25 | 25 | $shp->records[0]->DBFData['DESC'] = 'AAAAAAAAA'; |
@@ -334,6 +334,9 @@ |
||
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | + /** |
|
338 | + * @param string $error |
|
339 | + */ |
|
337 | 340 | function setError($error) { |
338 | 341 | $this->lastError = $error; |
339 | 342 | return false; |
@@ -35,60 +35,60 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @package bfShapeFiles |
37 | 37 | */ |
38 | - class ShapeFile { |
|
39 | - var $FileName; |
|
38 | + class ShapeFile { |
|
39 | + var $FileName; |
|
40 | 40 | |
41 | - var $SHPFile; |
|
42 | - var $SHXFile; |
|
43 | - var $DBFFile; |
|
41 | + var $SHPFile; |
|
42 | + var $SHXFile; |
|
43 | + var $DBFFile; |
|
44 | 44 | |
45 | - var $DBFHeader; |
|
45 | + var $DBFHeader; |
|
46 | 46 | |
47 | - var $lastError = ""; |
|
47 | + var $lastError = ""; |
|
48 | 48 | |
49 | - var $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0); |
|
50 | - var $fileLength = 0; |
|
51 | - var $shapeType = 0; |
|
49 | + var $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0); |
|
50 | + var $fileLength = 0; |
|
51 | + var $shapeType = 0; |
|
52 | 52 | |
53 | - var $records; |
|
53 | + var $records; |
|
54 | 54 | |
55 | - public function __construct($shapeType, $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0), $FileName = NULL) { |
|
55 | + public function __construct($shapeType, $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0), $FileName = NULL) { |
|
56 | 56 | $this->shapeType = $shapeType; |
57 | 57 | $this->boundingBox = $boundingBox; |
58 | 58 | $this->FileName = $FileName; |
59 | 59 | $this->fileLength = 50; // The value for file length is the total length of the file in 16-bit words (including the fifty 16-bit words that make up the header). |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | - function loadFromFile($FileName) { |
|
62 | + function loadFromFile($FileName) { |
|
63 | 63 | $this->FileName = $FileName; |
64 | 64 | |
65 | 65 | if (($this->_openSHPFile()) && ($this->_openDBFFile())) { |
66 | - $this->_loadHeaders(); |
|
67 | - $this->_loadRecords(); |
|
68 | - $this->_closeSHPFile(); |
|
69 | - $this->_closeDBFFile(); |
|
66 | + $this->_loadHeaders(); |
|
67 | + $this->_loadRecords(); |
|
68 | + $this->_closeSHPFile(); |
|
69 | + $this->_closeDBFFile(); |
|
70 | 70 | } else { |
71 | - return false; |
|
71 | + return false; |
|
72 | + } |
|
72 | 73 | } |
73 | - } |
|
74 | 74 | |
75 | - function saveToFile($FileName = NULL) { |
|
75 | + function saveToFile($FileName = NULL) { |
|
76 | 76 | if ($FileName != NULL) $this->FileName = $FileName; |
77 | 77 | |
78 | 78 | if (($this->_openSHPFile(TRUE)) && ($this->_openSHXFile(TRUE)) && ($this->_openDBFFile(TRUE))) { |
79 | - $this->_saveHeaders(); |
|
80 | - $this->_saveRecords(); |
|
81 | - $this->_closeSHPFile(); |
|
82 | - $this->_closeSHXFile(); |
|
83 | - $this->_closeDBFFile(); |
|
79 | + $this->_saveHeaders(); |
|
80 | + $this->_saveRecords(); |
|
81 | + $this->_closeSHPFile(); |
|
82 | + $this->_closeSHXFile(); |
|
83 | + $this->_closeDBFFile(); |
|
84 | 84 | } else { |
85 | - return false; |
|
85 | + return false; |
|
86 | + } |
|
86 | 87 | } |
87 | - } |
|
88 | 88 | |
89 | - function addRecord($record) { |
|
89 | + function addRecord($record) { |
|
90 | 90 | if ((isset($this->DBFHeader)) && (is_array($this->DBFHeader))) { |
91 | - $record->updateDBFInfo($this->DBFHeader); |
|
91 | + $record->updateDBFInfo($this->DBFHeader); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $this->fileLength += ($record->getContentLength() + 4); |
@@ -102,53 +102,53 @@ discard block |
||
102 | 102 | if ($this->boundingBox["ymax"]==0.0 || ($this->boundingBox["ymax"]<$record->SHPData["ymax"])) $this->boundingBox["ymax"] = $record->SHPData["ymax"]; |
103 | 103 | |
104 | 104 | if (in_array($this->shapeType,array(11,13,15,18,21,23,25,28))) { |
105 | - if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
106 | - if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
105 | + if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
106 | + if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | if (in_array($this->shapeType,array(11,13,15,18))) { |
110 | - if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
111 | - if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
110 | + if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
111 | + if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | return (count($this->records) - 1); |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - function deleteRecord($index) { |
|
117 | + function deleteRecord($index) { |
|
118 | 118 | if (isset($this->records[$index])) { |
119 | - $this->fileLength -= ($this->records[$index]->getContentLength() + 4); |
|
120 | - for ($i = $index; $i < (count($this->records) - 1); $i++) { |
|
121 | - $this->records[$i] = $this->records[$i + 1]; |
|
122 | - } |
|
123 | - unset($this->records[count($this->records) - 1]); |
|
124 | - $this->_deleteRecordFromDBF($index); |
|
119 | + $this->fileLength -= ($this->records[$index]->getContentLength() + 4); |
|
120 | + for ($i = $index; $i < (count($this->records) - 1); $i++) { |
|
121 | + $this->records[$i] = $this->records[$i + 1]; |
|
122 | + } |
|
123 | + unset($this->records[count($this->records) - 1]); |
|
124 | + $this->_deleteRecordFromDBF($index); |
|
125 | + } |
|
125 | 126 | } |
126 | - } |
|
127 | 127 | |
128 | - function getDBFHeader() { |
|
128 | + function getDBFHeader() { |
|
129 | 129 | return $this->DBFHeader; |
130 | - } |
|
130 | + } |
|
131 | 131 | |
132 | - function setDBFHeader($header) { |
|
132 | + function setDBFHeader($header) { |
|
133 | 133 | $this->DBFHeader = $header; |
134 | 134 | |
135 | 135 | for ($i = 0; $i < count($this->records); $i++) { |
136 | - $this->records[$i]->updateDBFInfo($header); |
|
136 | + $this->records[$i]->updateDBFInfo($header); |
|
137 | + } |
|
137 | 138 | } |
138 | - } |
|
139 | 139 | |
140 | - function getIndexFromDBFData($field, $value) { |
|
140 | + function getIndexFromDBFData($field, $value) { |
|
141 | 141 | $result = -1; |
142 | 142 | for ($i = 0; $i < (count($this->records) - 1); $i++) { |
143 | - if (isset($this->records[$i]->DBFData[$field]) && (strtoupper($this->records[$i]->DBFData[$field]) == strtoupper($value))) { |
|
144 | - $result = $i; |
|
145 | - } |
|
143 | + if (isset($this->records[$i]->DBFData[$field]) && (strtoupper($this->records[$i]->DBFData[$field]) == strtoupper($value))) { |
|
144 | + $result = $i; |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | return $result; |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | - function _loadDBFHeader() { |
|
151 | + function _loadDBFHeader() { |
|
152 | 152 | $DBFFile = fopen(str_replace('.*', '.dbf', $this->FileName), 'r'); |
153 | 153 | |
154 | 154 | $result = array(); |
@@ -157,40 +157,40 @@ discard block |
||
157 | 157 | $inHeader = true; |
158 | 158 | |
159 | 159 | while ($inHeader) { |
160 | - if (!feof($DBFFile)) { |
|
161 | - $buff32 = fread($DBFFile, 32); |
|
162 | - if ($i > 1) { |
|
160 | + if (!feof($DBFFile)) { |
|
161 | + $buff32 = fread($DBFFile, 32); |
|
162 | + if ($i > 1) { |
|
163 | 163 | if (substr($buff32, 0, 1) == chr(13)) { |
164 | - $inHeader = false; |
|
164 | + $inHeader = false; |
|
165 | 165 | } else { |
166 | - $pos = strpos(substr($buff32, 0, 10), chr(0)); |
|
167 | - $pos = ($pos == 0 ? 10 : $pos); |
|
166 | + $pos = strpos(substr($buff32, 0, 10), chr(0)); |
|
167 | + $pos = ($pos == 0 ? 10 : $pos); |
|
168 | 168 | |
169 | - $fieldName = substr($buff32, 0, $pos); |
|
170 | - $fieldType = substr($buff32, 11, 1); |
|
171 | - $fieldLen = ord(substr($buff32, 16, 1)); |
|
172 | - $fieldDec = ord(substr($buff32, 17, 1)); |
|
169 | + $fieldName = substr($buff32, 0, $pos); |
|
170 | + $fieldType = substr($buff32, 11, 1); |
|
171 | + $fieldLen = ord(substr($buff32, 16, 1)); |
|
172 | + $fieldDec = ord(substr($buff32, 17, 1)); |
|
173 | 173 | |
174 | - array_push($result, array($fieldName, $fieldType, $fieldLen, $fieldDec)); |
|
174 | + array_push($result, array($fieldName, $fieldType, $fieldLen, $fieldDec)); |
|
175 | + } |
|
175 | 176 | } |
176 | - } |
|
177 | - $i++; |
|
178 | - } else { |
|
179 | - $inHeader = false; |
|
180 | - } |
|
177 | + $i++; |
|
178 | + } else { |
|
179 | + $inHeader = false; |
|
180 | + } |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | fclose($DBFFile); |
184 | 184 | return($result); |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - function _deleteRecordFromDBF($index) { |
|
187 | + function _deleteRecordFromDBF($index) { |
|
188 | 188 | if (@dbase_delete_record($this->DBFFile, $index)) { |
189 | - @dbase_pack($this->DBFFile); |
|
189 | + @dbase_pack($this->DBFFile); |
|
190 | + } |
|
190 | 191 | } |
191 | - } |
|
192 | 192 | |
193 | - function _loadHeaders() { |
|
193 | + function _loadHeaders() { |
|
194 | 194 | fseek($this->SHPFile, 24, SEEK_SET); |
195 | 195 | $this->fileLength = Util::loadData("N", fread($this->SHPFile, 4)); |
196 | 196 | |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | $this->boundingBox["mmax"] = Util::loadData("d", fread($this->SHPFile, 8)); |
209 | 209 | |
210 | 210 | $this->DBFHeader = $this->_loadDBFHeader(); |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | - function _saveHeaders() { |
|
213 | + function _saveHeaders() { |
|
214 | 214 | fwrite($this->SHPFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0)); |
215 | 215 | fwrite($this->SHPFile, pack("N", $this->fileLength)); |
216 | 216 | fwrite($this->SHPFile, pack("V", 1000)); |
@@ -236,107 +236,107 @@ discard block |
||
236 | 236 | fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0)); |
237 | 237 | fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0)); |
238 | 238 | fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0)); |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | - function _loadRecords() { |
|
241 | + function _loadRecords() { |
|
242 | 242 | fseek($this->SHPFile, 100); |
243 | 243 | while (!feof($this->SHPFile)) { |
244 | - $bByte = ftell($this->SHPFile); |
|
245 | - $record = new ShapeRecord(-1); |
|
246 | - $record->loadFromFile($this->SHPFile, $this->DBFFile); |
|
247 | - $eByte = ftell($this->SHPFile); |
|
248 | - if (($eByte <= $bByte) || ($record->lastError != "")) { |
|
249 | - return false; |
|
250 | - } |
|
251 | - |
|
252 | - $this->records[] = $record; |
|
244 | + $bByte = ftell($this->SHPFile); |
|
245 | + $record = new ShapeRecord(-1); |
|
246 | + $record->loadFromFile($this->SHPFile, $this->DBFFile); |
|
247 | + $eByte = ftell($this->SHPFile); |
|
248 | + if (($eByte <= $bByte) || ($record->lastError != "")) { |
|
249 | + return false; |
|
250 | + } |
|
251 | + |
|
252 | + $this->records[] = $record; |
|
253 | + } |
|
253 | 254 | } |
254 | - } |
|
255 | 255 | |
256 | - function _saveRecords() { |
|
256 | + function _saveRecords() { |
|
257 | 257 | if (file_exists(str_replace('.*', '.dbf', $this->FileName))) { |
258 | - @unlink(str_replace('.*', '.dbf', $this->FileName)); |
|
258 | + @unlink(str_replace('.*', '.dbf', $this->FileName)); |
|
259 | 259 | } |
260 | 260 | if (!($this->DBFFile = @dbase_create(str_replace('.*', '.dbf', $this->FileName), $this->DBFHeader))) { |
261 | - return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
261 | + return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | $offset = 50; |
265 | 265 | if (is_array($this->records) && (count($this->records) > 0)) { |
266 | - reset($this->records); |
|
267 | - while (list($index, $record) = each($this->records)) { |
|
268 | - //Save the record to the .shp file |
|
269 | - $record->saveToFile($this->SHPFile, $this->DBFFile, $index + 1); |
|
270 | - |
|
271 | - //Save the record to the .shx file |
|
272 | - fwrite($this->SHXFile, pack("N", $offset)); |
|
273 | - fwrite($this->SHXFile, pack("N", $record->getContentLength())); |
|
274 | - $offset += (4 + $record->getContentLength()); |
|
275 | - } |
|
266 | + reset($this->records); |
|
267 | + while (list($index, $record) = each($this->records)) { |
|
268 | + //Save the record to the .shp file |
|
269 | + $record->saveToFile($this->SHPFile, $this->DBFFile, $index + 1); |
|
270 | + |
|
271 | + //Save the record to the .shx file |
|
272 | + fwrite($this->SHXFile, pack("N", $offset)); |
|
273 | + fwrite($this->SHXFile, pack("N", $record->getContentLength())); |
|
274 | + $offset += (4 + $record->getContentLength()); |
|
275 | + } |
|
276 | 276 | } |
277 | 277 | @dbase_pack($this->DBFFile); |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - function _openSHPFile($toWrite = false) { |
|
280 | + function _openSHPFile($toWrite = false) { |
|
281 | 281 | $this->SHPFile = @fopen(str_replace('.*', '.shp', $this->FileName), ($toWrite ? "wb+" : "rb")); |
282 | 282 | if (!$this->SHPFile) { |
283 | - return $this->setError(sprintf("It wasn't possible to open the Shape file '%s'", str_replace('.*', '.shp', $this->FileName))); |
|
283 | + return $this->setError(sprintf("It wasn't possible to open the Shape file '%s'", str_replace('.*', '.shp', $this->FileName))); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | return TRUE; |
287 | - } |
|
287 | + } |
|
288 | 288 | |
289 | - function _closeSHPFile() { |
|
289 | + function _closeSHPFile() { |
|
290 | 290 | if ($this->SHPFile) { |
291 | - fclose($this->SHPFile); |
|
292 | - $this->SHPFile = NULL; |
|
291 | + fclose($this->SHPFile); |
|
292 | + $this->SHPFile = NULL; |
|
293 | + } |
|
293 | 294 | } |
294 | - } |
|
295 | 295 | |
296 | - function _openSHXFile($toWrite = false) { |
|
296 | + function _openSHXFile($toWrite = false) { |
|
297 | 297 | $this->SHXFile = @fopen(str_replace('.*', '.shx', $this->FileName), ($toWrite ? "wb+" : "rb")); |
298 | 298 | if (!$this->SHXFile) { |
299 | - return $this->setError(sprintf("It wasn't possible to open the Index file '%s'", str_replace('.*', '.shx', $this->FileName))); |
|
299 | + return $this->setError(sprintf("It wasn't possible to open the Index file '%s'", str_replace('.*', '.shx', $this->FileName))); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | return TRUE; |
303 | - } |
|
303 | + } |
|
304 | 304 | |
305 | - function _closeSHXFile() { |
|
305 | + function _closeSHXFile() { |
|
306 | 306 | if ($this->SHXFile) { |
307 | - fclose($this->SHXFile); |
|
308 | - $this->SHXFile = NULL; |
|
307 | + fclose($this->SHXFile); |
|
308 | + $this->SHXFile = NULL; |
|
309 | + } |
|
309 | 310 | } |
310 | - } |
|
311 | 311 | |
312 | - function _openDBFFile($toWrite = false) { |
|
312 | + function _openDBFFile($toWrite = false) { |
|
313 | 313 | $checkFunction = $toWrite ? "is_writable" : "is_readable"; |
314 | 314 | if (($toWrite) && (!file_exists(str_replace('.*', '.dbf', $this->FileName)))) { |
315 | - if (!@dbase_create(str_replace('.*', '.dbf', $this->FileName), $this->DBFHeader)) { |
|
316 | - return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
317 | - } |
|
315 | + if (!@dbase_create(str_replace('.*', '.dbf', $this->FileName), $this->DBFHeader)) { |
|
316 | + return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
317 | + } |
|
318 | 318 | } |
319 | 319 | if ($checkFunction(str_replace('.*', '.dbf', $this->FileName))) { |
320 | - $this->DBFFile = dbase_open(str_replace('.*', '.dbf', $this->FileName), ($toWrite ? 2 : 0)); |
|
321 | - if (!$this->DBFFile) { |
|
322 | - return $this->setError(sprintf("It wasn't possible to open the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
323 | - } |
|
320 | + $this->DBFFile = dbase_open(str_replace('.*', '.dbf', $this->FileName), ($toWrite ? 2 : 0)); |
|
321 | + if (!$this->DBFFile) { |
|
322 | + return $this->setError(sprintf("It wasn't possible to open the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
323 | + } |
|
324 | 324 | } else { |
325 | - return $this->setError(sprintf("It wasn't possible to find the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
325 | + return $this->setError(sprintf("It wasn't possible to find the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName))); |
|
326 | 326 | } |
327 | 327 | return TRUE; |
328 | - } |
|
328 | + } |
|
329 | 329 | |
330 | - function _closeDBFFile() { |
|
330 | + function _closeDBFFile() { |
|
331 | 331 | if ($this->DBFFile) { |
332 | - dbase_close($this->DBFFile); |
|
333 | - $this->DBFFile = NULL; |
|
332 | + dbase_close($this->DBFFile); |
|
333 | + $this->DBFFile = NULL; |
|
334 | + } |
|
334 | 335 | } |
335 | - } |
|
336 | 336 | |
337 | - function setError($error) { |
|
337 | + function setError($error) { |
|
338 | 338 | $this->lastError = $error; |
339 | 339 | return false; |
340 | - } |
|
341 | - } |
|
340 | + } |
|
341 | + } |
|
342 | 342 |
@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | $this->records[] = $record; |
96 | 96 | $this->records[count($this->records) - 1]->recordNumber = count($this->records); |
97 | 97 | |
98 | - if ($this->boundingBox["xmin"]==0.0 || ($this->boundingBox["xmin"]>$record->SHPData["xmin"])) $this->boundingBox["xmin"] = $record->SHPData["xmin"]; |
|
99 | - if ($this->boundingBox["xmax"]==0.0 || ($this->boundingBox["xmax"]<$record->SHPData["xmax"])) $this->boundingBox["xmax"] = $record->SHPData["xmax"]; |
|
98 | + if ($this->boundingBox["xmin"] == 0.0 || ($this->boundingBox["xmin"] > $record->SHPData["xmin"])) $this->boundingBox["xmin"] = $record->SHPData["xmin"]; |
|
99 | + if ($this->boundingBox["xmax"] == 0.0 || ($this->boundingBox["xmax"] < $record->SHPData["xmax"])) $this->boundingBox["xmax"] = $record->SHPData["xmax"]; |
|
100 | 100 | |
101 | - if ($this->boundingBox["ymin"]==0.0 || ($this->boundingBox["ymin"]>$record->SHPData["ymin"])) $this->boundingBox["ymin"] = $record->SHPData["ymin"]; |
|
102 | - if ($this->boundingBox["ymax"]==0.0 || ($this->boundingBox["ymax"]<$record->SHPData["ymax"])) $this->boundingBox["ymax"] = $record->SHPData["ymax"]; |
|
101 | + if ($this->boundingBox["ymin"] == 0.0 || ($this->boundingBox["ymin"] > $record->SHPData["ymin"])) $this->boundingBox["ymin"] = $record->SHPData["ymin"]; |
|
102 | + if ($this->boundingBox["ymax"] == 0.0 || ($this->boundingBox["ymax"] < $record->SHPData["ymax"])) $this->boundingBox["ymax"] = $record->SHPData["ymax"]; |
|
103 | 103 | |
104 | - if (in_array($this->shapeType,array(11,13,15,18,21,23,25,28))) { |
|
105 | - if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
106 | - if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
104 | + if (in_array($this->shapeType, array(11, 13, 15, 18, 21, 23, 25, 28))) { |
|
105 | + if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"] == 0.0 || ($this->boundingBox["mmin"] > $record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
106 | + if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"] == 0.0 || ($this->boundingBox["mmax"] < $record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
107 | 107 | } |
108 | 108 | |
109 | - if (in_array($this->shapeType,array(11,13,15,18))) { |
|
110 | - if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
111 | - if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
109 | + if (in_array($this->shapeType, array(11, 13, 15, 18))) { |
|
110 | + if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"] == 0.0 || ($this->boundingBox["zmin"] > $record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
111 | + if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"] == 0.0 || ($this->boundingBox["zmax"] < $record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | return (count($this->records) - 1); |
@@ -219,23 +219,23 @@ discard block |
||
219 | 219 | fwrite($this->SHPFile, Util::packDouble($this->boundingBox['ymin'])); |
220 | 220 | fwrite($this->SHPFile, Util::packDouble($this->boundingBox['xmax'])); |
221 | 221 | fwrite($this->SHPFile, Util::packDouble($this->boundingBox['ymax'])); |
222 | - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0)); |
|
223 | - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0)); |
|
224 | - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0)); |
|
225 | - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0)); |
|
222 | + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmin']) ? $this->boundingBox['zmin'] : 0)); |
|
223 | + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmax']) ? $this->boundingBox['zmax'] : 0)); |
|
224 | + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmin']) ? $this->boundingBox['mmin'] : 0)); |
|
225 | + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmax']) ? $this->boundingBox['mmax'] : 0)); |
|
226 | 226 | |
227 | 227 | fwrite($this->SHXFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0)); |
228 | - fwrite($this->SHXFile, pack("N", 50 + 4*count($this->records))); |
|
228 | + fwrite($this->SHXFile, pack("N", 50 + 4 * count($this->records))); |
|
229 | 229 | fwrite($this->SHXFile, pack("V", 1000)); |
230 | 230 | fwrite($this->SHXFile, pack("V", $this->shapeType)); |
231 | 231 | fwrite($this->SHXFile, Util::packDouble($this->boundingBox['xmin'])); |
232 | 232 | fwrite($this->SHXFile, Util::packDouble($this->boundingBox['ymin'])); |
233 | 233 | fwrite($this->SHXFile, Util::packDouble($this->boundingBox['xmax'])); |
234 | 234 | fwrite($this->SHXFile, Util::packDouble($this->boundingBox['ymax'])); |
235 | - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0)); |
|
236 | - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0)); |
|
237 | - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0)); |
|
238 | - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0)); |
|
235 | + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmin']) ? $this->boundingBox['zmin'] : 0)); |
|
236 | + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmax']) ? $this->boundingBox['zmax'] : 0)); |
|
237 | + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmin']) ? $this->boundingBox['mmin'] : 0)); |
|
238 | + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmax']) ? $this->boundingBox['mmax'] : 0)); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | function _loadRecords() { |
@@ -73,7 +73,9 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | function saveToFile($FileName = NULL) { |
76 | - if ($FileName != NULL) $this->FileName = $FileName; |
|
76 | + if ($FileName != NULL) { |
|
77 | + $this->FileName = $FileName; |
|
78 | + } |
|
77 | 79 | |
78 | 80 | if (($this->_openSHPFile(TRUE)) && ($this->_openSHXFile(TRUE)) && ($this->_openDBFFile(TRUE))) { |
79 | 81 | $this->_saveHeaders(); |
@@ -95,20 +97,36 @@ discard block |
||
95 | 97 | $this->records[] = $record; |
96 | 98 | $this->records[count($this->records) - 1]->recordNumber = count($this->records); |
97 | 99 | |
98 | - if ($this->boundingBox["xmin"]==0.0 || ($this->boundingBox["xmin"]>$record->SHPData["xmin"])) $this->boundingBox["xmin"] = $record->SHPData["xmin"]; |
|
99 | - if ($this->boundingBox["xmax"]==0.0 || ($this->boundingBox["xmax"]<$record->SHPData["xmax"])) $this->boundingBox["xmax"] = $record->SHPData["xmax"]; |
|
100 | + if ($this->boundingBox["xmin"]==0.0 || ($this->boundingBox["xmin"]>$record->SHPData["xmin"])) { |
|
101 | + $this->boundingBox["xmin"] = $record->SHPData["xmin"]; |
|
102 | + } |
|
103 | + if ($this->boundingBox["xmax"]==0.0 || ($this->boundingBox["xmax"]<$record->SHPData["xmax"])) { |
|
104 | + $this->boundingBox["xmax"] = $record->SHPData["xmax"]; |
|
105 | + } |
|
100 | 106 | |
101 | - if ($this->boundingBox["ymin"]==0.0 || ($this->boundingBox["ymin"]>$record->SHPData["ymin"])) $this->boundingBox["ymin"] = $record->SHPData["ymin"]; |
|
102 | - if ($this->boundingBox["ymax"]==0.0 || ($this->boundingBox["ymax"]<$record->SHPData["ymax"])) $this->boundingBox["ymax"] = $record->SHPData["ymax"]; |
|
107 | + if ($this->boundingBox["ymin"]==0.0 || ($this->boundingBox["ymin"]>$record->SHPData["ymin"])) { |
|
108 | + $this->boundingBox["ymin"] = $record->SHPData["ymin"]; |
|
109 | + } |
|
110 | + if ($this->boundingBox["ymax"]==0.0 || ($this->boundingBox["ymax"]<$record->SHPData["ymax"])) { |
|
111 | + $this->boundingBox["ymax"] = $record->SHPData["ymax"]; |
|
112 | + } |
|
103 | 113 | |
104 | 114 | if (in_array($this->shapeType,array(11,13,15,18,21,23,25,28))) { |
105 | - if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
106 | - if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
115 | + if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) { |
|
116 | + $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
117 | + } |
|
118 | + if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) { |
|
119 | + $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
120 | + } |
|
107 | 121 | } |
108 | 122 | |
109 | 123 | if (in_array($this->shapeType,array(11,13,15,18))) { |
110 | - if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
111 | - if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
124 | + if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) { |
|
125 | + $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
126 | + } |
|
127 | + if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) { |
|
128 | + $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
129 | + } |
|
112 | 130 | } |
113 | 131 | |
114 | 132 | return (count($this->records) - 1); |
@@ -42,6 +42,9 @@ discard block |
||
42 | 42 | var $SHPData = array(); |
43 | 43 | var $DBFData = array(); |
44 | 44 | |
45 | + /** |
|
46 | + * @param integer $shapeType |
|
47 | + */ |
|
45 | 48 | public function __construct($shapeType) { |
46 | 49 | $this->shapeType = $shapeType; |
47 | 50 | } |
@@ -275,6 +278,9 @@ discard block |
||
275 | 278 | } |
276 | 279 | } |
277 | 280 | |
281 | + /** |
|
282 | + * @param string $type |
|
283 | + */ |
|
278 | 284 | function _loadMultiPointMZRecord( $type ) { |
279 | 285 | |
280 | 286 | $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -308,6 +314,9 @@ discard block |
||
308 | 314 | } |
309 | 315 | } |
310 | 316 | |
317 | + /** |
|
318 | + * @param string $type |
|
319 | + */ |
|
311 | 320 | function _saveMultiPointMZRecord( $type ) { |
312 | 321 | |
313 | 322 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
@@ -361,6 +370,9 @@ discard block |
||
361 | 370 | fseek($this->SHPFile, $firstIndex + ($readPoints*16)); |
362 | 371 | } |
363 | 372 | |
373 | + /** |
|
374 | + * @param string $type |
|
375 | + */ |
|
364 | 376 | function _loadPolyLineMZRecord( $type ) { |
365 | 377 | |
366 | 378 | $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -409,6 +421,9 @@ discard block |
||
409 | 421 | } |
410 | 422 | } |
411 | 423 | |
424 | + /** |
|
425 | + * @param string $type |
|
426 | + */ |
|
412 | 427 | function _savePolyLineMZRecord( $type ) { |
413 | 428 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
414 | 429 | |
@@ -641,6 +656,9 @@ discard block |
||
641 | 656 | } |
642 | 657 | } |
643 | 658 | |
659 | + /** |
|
660 | + * @param string $error |
|
661 | + */ |
|
644 | 662 | function setError($error) { |
645 | 663 | $this->lastError = $error; |
646 | 664 | return false; |
@@ -30,159 +30,159 @@ discard block |
||
30 | 30 | */ |
31 | 31 | namespace ShapeFile; |
32 | 32 | |
33 | - class ShapeRecord { |
|
34 | - var $SHPFile = NULL; |
|
35 | - var $DBFFile = NULL; |
|
33 | + class ShapeRecord { |
|
34 | + var $SHPFile = NULL; |
|
35 | + var $DBFFile = NULL; |
|
36 | 36 | |
37 | - var $recordNumber = NULL; |
|
38 | - var $shapeType = NULL; |
|
37 | + var $recordNumber = NULL; |
|
38 | + var $shapeType = NULL; |
|
39 | 39 | |
40 | - var $lastError = ""; |
|
40 | + var $lastError = ""; |
|
41 | 41 | |
42 | - var $SHPData = array(); |
|
43 | - var $DBFData = array(); |
|
42 | + var $SHPData = array(); |
|
43 | + var $DBFData = array(); |
|
44 | 44 | |
45 | - public function __construct($shapeType) { |
|
45 | + public function __construct($shapeType) { |
|
46 | 46 | $this->shapeType = $shapeType; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - function loadFromFile(&$SHPFile, &$DBFFile) { |
|
49 | + function loadFromFile(&$SHPFile, &$DBFFile) { |
|
50 | 50 | $this->SHPFile = $SHPFile; |
51 | 51 | $this->DBFFile = $DBFFile; |
52 | 52 | $this->_loadHeaders(); |
53 | 53 | |
54 | 54 | switch ($this->shapeType) { |
55 | - case 0: |
|
55 | + case 0: |
|
56 | 56 | $this->_loadNullRecord(); |
57 | - break; |
|
58 | - case 1: |
|
57 | + break; |
|
58 | + case 1: |
|
59 | 59 | $this->_loadPointRecord(); |
60 | - break; |
|
61 | - case 21: |
|
60 | + break; |
|
61 | + case 21: |
|
62 | 62 | $this->_loadPointMRecord(); |
63 | - break; |
|
64 | - case 11: |
|
63 | + break; |
|
64 | + case 11: |
|
65 | 65 | $this->_loadPointZRecord(); |
66 | - break; |
|
67 | - case 3: |
|
66 | + break; |
|
67 | + case 3: |
|
68 | 68 | $this->_loadPolyLineRecord(); |
69 | - break; |
|
70 | - case 23: |
|
69 | + break; |
|
70 | + case 23: |
|
71 | 71 | $this->_loadPolyLineMRecord(); |
72 | - break; |
|
73 | - case 13: |
|
72 | + break; |
|
73 | + case 13: |
|
74 | 74 | $this->_loadPolyLineZRecord(); |
75 | - break; |
|
76 | - case 5: |
|
75 | + break; |
|
76 | + case 5: |
|
77 | 77 | $this->_loadPolygonRecord(); |
78 | - break; |
|
79 | - case 25: |
|
78 | + break; |
|
79 | + case 25: |
|
80 | 80 | $this->_loadPolygonMRecord(); |
81 | - break; |
|
82 | - case 15: |
|
81 | + break; |
|
82 | + case 15: |
|
83 | 83 | $this->_loadPolygonZRecord(); |
84 | - break; |
|
85 | - case 8: |
|
84 | + break; |
|
85 | + case 8: |
|
86 | 86 | $this->_loadMultiPointRecord(); |
87 | - break; |
|
88 | - case 28: |
|
87 | + break; |
|
88 | + case 28: |
|
89 | 89 | $this->_loadMultiPointMRecord(); |
90 | - break; |
|
91 | - case 18: |
|
90 | + break; |
|
91 | + case 18: |
|
92 | 92 | $this->_loadMultiPointZRecord(); |
93 | - break; |
|
94 | - default: |
|
93 | + break; |
|
94 | + default: |
|
95 | 95 | $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
96 | - break; |
|
96 | + break; |
|
97 | 97 | } |
98 | 98 | $this->_loadDBFData(); |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - function saveToFile(&$SHPFile, &$DBFFile, $recordNumber) { |
|
101 | + function saveToFile(&$SHPFile, &$DBFFile, $recordNumber) { |
|
102 | 102 | $this->SHPFile = $SHPFile; |
103 | 103 | $this->DBFFile = $DBFFile; |
104 | 104 | $this->recordNumber = $recordNumber; |
105 | 105 | $this->_saveHeaders(); |
106 | 106 | |
107 | 107 | switch ($this->shapeType) { |
108 | - case 0: |
|
108 | + case 0: |
|
109 | 109 | $this->_saveNullRecord(); |
110 | - break; |
|
111 | - case 1: |
|
110 | + break; |
|
111 | + case 1: |
|
112 | 112 | $this->_savePointRecord(); |
113 | - break; |
|
114 | - case 21: |
|
113 | + break; |
|
114 | + case 21: |
|
115 | 115 | $this->_savePointMRecord(); |
116 | - break; |
|
117 | - case 11: |
|
116 | + break; |
|
117 | + case 11: |
|
118 | 118 | $this->_savePointZRecord(); |
119 | - break; |
|
120 | - case 3: |
|
119 | + break; |
|
120 | + case 3: |
|
121 | 121 | $this->_savePolyLineRecord(); |
122 | - break; |
|
123 | - case 23: |
|
122 | + break; |
|
123 | + case 23: |
|
124 | 124 | $this->_savePolyLineMRecord(); |
125 | - break; |
|
126 | - case 13: |
|
125 | + break; |
|
126 | + case 13: |
|
127 | 127 | $this->_savePolyLineZRecord(); |
128 | - break; |
|
129 | - case 5: |
|
128 | + break; |
|
129 | + case 5: |
|
130 | 130 | $this->_savePolygonRecord(); |
131 | - break; |
|
132 | - case 25: |
|
131 | + break; |
|
132 | + case 25: |
|
133 | 133 | $this->_savePolygonMRecord(); |
134 | - break; |
|
135 | - case 15: |
|
134 | + break; |
|
135 | + case 15: |
|
136 | 136 | $this->_savePolygonZRecord(); |
137 | - break; |
|
138 | - case 8: |
|
137 | + break; |
|
138 | + case 8: |
|
139 | 139 | $this->_saveMultiPointRecord(); |
140 | - break; |
|
141 | - case 28: |
|
140 | + break; |
|
141 | + case 28: |
|
142 | 142 | $this->_saveMultiPointMRecord(); |
143 | - break; |
|
144 | - case 18: |
|
143 | + break; |
|
144 | + case 18: |
|
145 | 145 | $this->_saveMultiPointZRecord(); |
146 | - break; |
|
147 | - default: |
|
146 | + break; |
|
147 | + default: |
|
148 | 148 | $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
149 | - break; |
|
149 | + break; |
|
150 | 150 | } |
151 | 151 | $this->_saveDBFData(); |
152 | - } |
|
152 | + } |
|
153 | 153 | |
154 | - function updateDBFInfo($header) { |
|
154 | + function updateDBFInfo($header) { |
|
155 | 155 | $tmp = $this->DBFData; |
156 | 156 | unset($this->DBFData); |
157 | 157 | $this->DBFData = array(); |
158 | 158 | reset($header); |
159 | 159 | while (list($key, $value) = each($header)) { |
160 | - $this->DBFData[$value[0]] = (isset($tmp[$value[0]])) ? $tmp[$value[0]] : ""; |
|
160 | + $this->DBFData[$value[0]] = (isset($tmp[$value[0]])) ? $tmp[$value[0]] : ""; |
|
161 | + } |
|
161 | 162 | } |
162 | - } |
|
163 | 163 | |
164 | - function _loadHeaders() { |
|
164 | + function _loadHeaders() { |
|
165 | 165 | $this->recordNumber = Util::loadData("N", fread($this->SHPFile, 4)); |
166 | 166 | $tmp = Util::loadData("N", fread($this->SHPFile, 4)); //We read the length of the record |
167 | 167 | $this->shapeType = Util::loadData("V", fread($this->SHPFile, 4)); |
168 | - } |
|
168 | + } |
|
169 | 169 | |
170 | - function _saveHeaders() { |
|
170 | + function _saveHeaders() { |
|
171 | 171 | fwrite($this->SHPFile, pack("N", $this->recordNumber)); |
172 | 172 | fwrite($this->SHPFile, pack("N", $this->getContentLength())); |
173 | 173 | fwrite($this->SHPFile, pack("V", $this->shapeType)); |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - function _loadPoint() { |
|
176 | + function _loadPoint() { |
|
177 | 177 | $data = array(); |
178 | 178 | |
179 | 179 | $data["x"] = Util::loadData("d", fread($this->SHPFile, 8)); |
180 | 180 | $data["y"] = Util::loadData("d", fread($this->SHPFile, 8)); |
181 | 181 | |
182 | 182 | return $data; |
183 | - } |
|
183 | + } |
|
184 | 184 | |
185 | - function _loadPointM() { |
|
185 | + function _loadPointM() { |
|
186 | 186 | $data = array(); |
187 | 187 | |
188 | 188 | $data["x"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | $data["m"] = Util::loadData("d", fread($this->SHPFile, 8)); |
191 | 191 | |
192 | 192 | return $data; |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - function _loadPointZ() { |
|
195 | + function _loadPointZ() { |
|
196 | 196 | $data = array(); |
197 | 197 | |
198 | 198 | $data["x"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -201,67 +201,67 @@ discard block |
||
201 | 201 | $data["m"] = Util::loadData("d", fread($this->SHPFile, 8)); |
202 | 202 | |
203 | 203 | return $data; |
204 | - } |
|
204 | + } |
|
205 | 205 | |
206 | - function _savePoint($data) { |
|
206 | + function _savePoint($data) { |
|
207 | 207 | fwrite($this->SHPFile, Util::packDouble($data["x"])); |
208 | 208 | fwrite($this->SHPFile, Util::packDouble($data["y"])); |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - function _savePointM($data) { |
|
211 | + function _savePointM($data) { |
|
212 | 212 | fwrite($this->SHPFile, Util::packDouble($data["x"])); |
213 | 213 | fwrite($this->SHPFile, Util::packDouble($data["y"])); |
214 | 214 | fwrite($this->SHPFile, Util::packDouble($data["m"])); |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - function _savePointZ($data) { |
|
217 | + function _savePointZ($data) { |
|
218 | 218 | fwrite($this->SHPFile, Util::packDouble($data["x"])); |
219 | 219 | fwrite($this->SHPFile, Util::packDouble($data["y"])); |
220 | 220 | fwrite($this->SHPFile, Util::packDouble($data["z"])); |
221 | 221 | fwrite($this->SHPFile, Util::packDouble($data["m"])); |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - function _saveMeasure($data) { |
|
224 | + function _saveMeasure($data) { |
|
225 | 225 | fwrite($this->SHPFile, Util::packDouble($data["m"])); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - function _saveZCoordinate($data) { |
|
228 | + function _saveZCoordinate($data) { |
|
229 | 229 | fwrite($this->SHPFile, Util::packDouble($data["z"])); |
230 | - } |
|
230 | + } |
|
231 | 231 | |
232 | - function _loadNullRecord() { |
|
232 | + function _loadNullRecord() { |
|
233 | 233 | $this->SHPData = array(); |
234 | - } |
|
234 | + } |
|
235 | 235 | |
236 | - function _saveNullRecord() { |
|
236 | + function _saveNullRecord() { |
|
237 | 237 | //Don't save anything |
238 | - } |
|
238 | + } |
|
239 | 239 | |
240 | - function _loadPointRecord() { |
|
240 | + function _loadPointRecord() { |
|
241 | 241 | $this->SHPData = $this->_loadPoint(); |
242 | - } |
|
242 | + } |
|
243 | 243 | |
244 | - function _loadPointMRecord() { |
|
244 | + function _loadPointMRecord() { |
|
245 | 245 | $this->SHPData = $this->_loadPointM(); |
246 | - } |
|
246 | + } |
|
247 | 247 | |
248 | - function _loadPointZRecord() { |
|
248 | + function _loadPointZRecord() { |
|
249 | 249 | $this->SHPData = $this->_loadPointZ(); |
250 | - } |
|
250 | + } |
|
251 | 251 | |
252 | - function _savePointRecord() { |
|
252 | + function _savePointRecord() { |
|
253 | 253 | $this->_savePoint($this->SHPData); |
254 | - } |
|
254 | + } |
|
255 | 255 | |
256 | - function _savePointMRecord() { |
|
256 | + function _savePointMRecord() { |
|
257 | 257 | $this->_savePointM($this->SHPData); |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | - function _savePointZRecord() { |
|
260 | + function _savePointZRecord() { |
|
261 | 261 | $this->_savePointZ($this->SHPData); |
262 | - } |
|
262 | + } |
|
263 | 263 | |
264 | - function _loadMultiPointRecord() { |
|
264 | + function _loadMultiPointRecord() { |
|
265 | 265 | $this->SHPData = array(); |
266 | 266 | $this->SHPData["xmin"] = Util::loadData("d", fread($this->SHPFile, 8)); |
267 | 267 | $this->SHPData["ymin"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -271,66 +271,66 @@ discard block |
||
271 | 271 | $this->SHPData["numpoints"] = Util::loadData("V", fread($this->SHPFile, 4)); |
272 | 272 | |
273 | 273 | for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) { |
274 | - $this->SHPData["points"][] = $this->_loadPoint(); |
|
274 | + $this->SHPData["points"][] = $this->_loadPoint(); |
|
275 | + } |
|
275 | 276 | } |
276 | - } |
|
277 | 277 | |
278 | - function _loadMultiPointMZRecord( $type ) { |
|
278 | + function _loadMultiPointMZRecord( $type ) { |
|
279 | 279 | |
280 | 280 | $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); |
281 | 281 | $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8)); |
282 | 282 | |
283 | 283 | for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) { |
284 | - $this->SHPData["points"][$i][$type] = Util::loadData("d", fread($this->SHPFile, 8)); |
|
284 | + $this->SHPData["points"][$i][$type] = Util::loadData("d", fread($this->SHPFile, 8)); |
|
285 | + } |
|
285 | 286 | } |
286 | - } |
|
287 | 287 | |
288 | - function _loadMultiPointMRecord() { |
|
288 | + function _loadMultiPointMRecord() { |
|
289 | 289 | $this->_loadMultiPointRecord(); |
290 | 290 | |
291 | 291 | $this->_loadMultiPointMZRecord("m"); |
292 | - } |
|
292 | + } |
|
293 | 293 | |
294 | - function _loadMultiPointZRecord() { |
|
294 | + function _loadMultiPointZRecord() { |
|
295 | 295 | $this->_loadMultiPointRecord(); |
296 | 296 | |
297 | 297 | $this->_loadMultiPointMZRecord("z"); |
298 | 298 | $this->_loadMultiPointMZRecord("m"); |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - function _saveMultiPointRecord() { |
|
301 | + function _saveMultiPointRecord() { |
|
302 | 302 | fwrite($this->SHPFile, pack("dddd", $this->SHPData["xmin"], $this->SHPData["ymin"], $this->SHPData["xmax"], $this->SHPData["ymax"])); |
303 | 303 | |
304 | 304 | fwrite($this->SHPFile, pack("V", $this->SHPData["numpoints"])); |
305 | 305 | |
306 | 306 | for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) { |
307 | - $this->_savePoint($this->SHPData["points"][$i]); |
|
307 | + $this->_savePoint($this->SHPData["points"][$i]); |
|
308 | + } |
|
308 | 309 | } |
309 | - } |
|
310 | 310 | |
311 | - function _saveMultiPointMZRecord( $type ) { |
|
311 | + function _saveMultiPointMZRecord( $type ) { |
|
312 | 312 | |
313 | 313 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
314 | 314 | |
315 | 315 | for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) { |
316 | - fwrite($this->SHPFile, Util::packDouble($this->SHPData["points"][$type])); |
|
316 | + fwrite($this->SHPFile, Util::packDouble($this->SHPData["points"][$type])); |
|
317 | + } |
|
317 | 318 | } |
318 | - } |
|
319 | 319 | |
320 | - function _saveMultiPointMRecord() { |
|
320 | + function _saveMultiPointMRecord() { |
|
321 | 321 | $this->_saveMultiPointRecord(); |
322 | 322 | |
323 | 323 | $this->_saveMultiPointMZRecord("m"); |
324 | - } |
|
324 | + } |
|
325 | 325 | |
326 | - function _saveMultiPointZRecord() { |
|
326 | + function _saveMultiPointZRecord() { |
|
327 | 327 | $this->_saveMultiPointRecord(); |
328 | 328 | |
329 | 329 | $this->_saveMultiPointMZRecord("z"); |
330 | 330 | $this->_saveMultiPointMZRecord("m"); |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - function _loadPolyLineRecord() { |
|
333 | + function _loadPolyLineRecord() { |
|
334 | 334 | $this->SHPData = array(); |
335 | 335 | $this->SHPData["xmin"] = Util::loadData("d", fread($this->SHPFile, 8)); |
336 | 336 | $this->SHPData["ymin"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -341,27 +341,27 @@ discard block |
||
341 | 341 | $this->SHPData["numpoints"] = Util::loadData("V", fread($this->SHPFile, 4)); |
342 | 342 | |
343 | 343 | for ($i = 0; $i < $this->SHPData["numparts"]; $i++) { |
344 | - $this->SHPData["parts"][$i] = Util::loadData("V", fread($this->SHPFile, 4)); |
|
344 | + $this->SHPData["parts"][$i] = Util::loadData("V", fread($this->SHPFile, 4)); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $firstIndex = ftell($this->SHPFile); |
348 | 348 | $readPoints = 0; |
349 | 349 | reset($this->SHPData["parts"]); |
350 | 350 | while (list($partIndex, $partData) = each($this->SHPData["parts"])) { |
351 | - if (!isset($this->SHPData["parts"][$partIndex]["points"]) || !is_array($this->SHPData["parts"][$partIndex]["points"])) { |
|
352 | - $this->SHPData["parts"][$partIndex] = array(); |
|
353 | - $this->SHPData["parts"][$partIndex]["points"] = array(); |
|
354 | - } |
|
355 | - while (!in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) && !feof($this->SHPFile)) { |
|
356 | - $this->SHPData["parts"][$partIndex]["points"][] = $this->_loadPoint(); |
|
357 | - $readPoints++; |
|
358 | - } |
|
351 | + if (!isset($this->SHPData["parts"][$partIndex]["points"]) || !is_array($this->SHPData["parts"][$partIndex]["points"])) { |
|
352 | + $this->SHPData["parts"][$partIndex] = array(); |
|
353 | + $this->SHPData["parts"][$partIndex]["points"] = array(); |
|
354 | + } |
|
355 | + while (!in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) && !feof($this->SHPFile)) { |
|
356 | + $this->SHPData["parts"][$partIndex]["points"][] = $this->_loadPoint(); |
|
357 | + $readPoints++; |
|
358 | + } |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | fseek($this->SHPFile, $firstIndex + ($readPoints*16)); |
362 | - } |
|
362 | + } |
|
363 | 363 | |
364 | - function _loadPolyLineMZRecord( $type ) { |
|
364 | + function _loadPolyLineMZRecord( $type ) { |
|
365 | 365 | |
366 | 366 | $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); |
367 | 367 | $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -370,170 +370,170 @@ discard block |
||
370 | 370 | $readPoints = 0; |
371 | 371 | reset($this->SHPData["parts"]); |
372 | 372 | while (list($partIndex, $partData) = each($this->SHPData["parts"])) { |
373 | - while (!in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) && !feof($this->SHPFile)) { |
|
374 | - $this->SHPData["parts"][$partIndex]["points"][$readPoints][$type] = Util::loadData("d", fread($this->SHPFile, 8)); |
|
375 | - $readPoints++; |
|
376 | - } |
|
373 | + while (!in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) && !feof($this->SHPFile)) { |
|
374 | + $this->SHPData["parts"][$partIndex]["points"][$readPoints][$type] = Util::loadData("d", fread($this->SHPFile, 8)); |
|
375 | + $readPoints++; |
|
376 | + } |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | fseek($this->SHPFile, $firstIndex + ($readPoints*24)); |
380 | - } |
|
380 | + } |
|
381 | 381 | |
382 | - function _loadPolyLineMRecord() { |
|
382 | + function _loadPolyLineMRecord() { |
|
383 | 383 | $this->_loadPolyLineRecord(); |
384 | 384 | |
385 | 385 | $this->_loadPolyLineMZRecord("m"); |
386 | - } |
|
386 | + } |
|
387 | 387 | |
388 | - function _loadPolyLineZRecord() { |
|
388 | + function _loadPolyLineZRecord() { |
|
389 | 389 | $this->_loadPolyLineRecord(); |
390 | 390 | |
391 | 391 | $this->_loadPolyLineMZRecord("z"); |
392 | 392 | $this->_loadPolyLineMZRecord("m"); |
393 | - } |
|
393 | + } |
|
394 | 394 | |
395 | - function _savePolyLineRecord() { |
|
395 | + function _savePolyLineRecord() { |
|
396 | 396 | fwrite($this->SHPFile, pack("dddd", $this->SHPData["xmin"], $this->SHPData["ymin"], $this->SHPData["xmax"], $this->SHPData["ymax"])); |
397 | 397 | |
398 | 398 | fwrite($this->SHPFile, pack("VV", $this->SHPData["numparts"], $this->SHPData["numpoints"])); |
399 | 399 | |
400 | 400 | for ($i = 0; $i < $this->SHPData["numparts"]; $i++) { |
401 | - fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i])-1)); |
|
401 | + fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i])-1)); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | foreach ($this->SHPData["parts"] as $partData){ |
405 | - reset($partData["points"]); |
|
406 | - while (list($pointIndex, $pointData) = each($partData["points"])) { |
|
407 | - $this->_savePoint($pointData); |
|
408 | - } |
|
405 | + reset($partData["points"]); |
|
406 | + while (list($pointIndex, $pointData) = each($partData["points"])) { |
|
407 | + $this->_savePoint($pointData); |
|
408 | + } |
|
409 | + } |
|
409 | 410 | } |
410 | - } |
|
411 | 411 | |
412 | - function _savePolyLineMZRecord( $type ) { |
|
412 | + function _savePolyLineMZRecord( $type ) { |
|
413 | 413 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
414 | 414 | |
415 | 415 | foreach ($this->SHPData["parts"] as $partData){ |
416 | - reset($partData["points"]); |
|
417 | - while (list($pointIndex, $pointData) = each($partData["points"])) { |
|
418 | - fwrite($this->SHPFile, Util::packDouble($pointData[$type])); |
|
419 | - } |
|
416 | + reset($partData["points"]); |
|
417 | + while (list($pointIndex, $pointData) = each($partData["points"])) { |
|
418 | + fwrite($this->SHPFile, Util::packDouble($pointData[$type])); |
|
419 | + } |
|
420 | + } |
|
420 | 421 | } |
421 | - } |
|
422 | 422 | |
423 | - function _savePolyLineMRecord() { |
|
423 | + function _savePolyLineMRecord() { |
|
424 | 424 | $this->_savePolyLineRecord(); |
425 | 425 | |
426 | 426 | $this->_savePolyLineMZRecord("m"); |
427 | - } |
|
427 | + } |
|
428 | 428 | |
429 | - function _savePolyLineZRecord() { |
|
429 | + function _savePolyLineZRecord() { |
|
430 | 430 | $this->_savePolyLineRecord(); |
431 | 431 | |
432 | 432 | $this->_savePolyLineMZRecord("z"); |
433 | 433 | $this->_savePolyLineMZRecord("m"); |
434 | - } |
|
434 | + } |
|
435 | 435 | |
436 | - function _loadPolygonRecord() { |
|
436 | + function _loadPolygonRecord() { |
|
437 | 437 | $this->_loadPolyLineRecord(); |
438 | - } |
|
438 | + } |
|
439 | 439 | |
440 | - function _loadPolygonMRecord() { |
|
440 | + function _loadPolygonMRecord() { |
|
441 | 441 | $this->_loadPolyLineMRecord(); |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - function _loadPolygonZRecord() { |
|
444 | + function _loadPolygonZRecord() { |
|
445 | 445 | $this->_loadPolyLineZRecord(); |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - function _savePolygonRecord() { |
|
448 | + function _savePolygonRecord() { |
|
449 | 449 | $this->_savePolyLineRecord(); |
450 | - } |
|
450 | + } |
|
451 | 451 | |
452 | - function _savePolygonMRecord() { |
|
452 | + function _savePolygonMRecord() { |
|
453 | 453 | $this->_savePolyLineMRecord(); |
454 | - } |
|
454 | + } |
|
455 | 455 | |
456 | - function _savePolygonZRecord() { |
|
456 | + function _savePolygonZRecord() { |
|
457 | 457 | $this->_savePolyLineZRecord(); |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - function addPoint($point, $partIndex = 0) { |
|
460 | + function addPoint($point, $partIndex = 0) { |
|
461 | 461 | switch ($this->shapeType) { |
462 | - case 0: |
|
462 | + case 0: |
|
463 | 463 | //Don't add anything |
464 | 464 | break; |
465 | - case 1: |
|
465 | + case 1: |
|
466 | 466 | case 11: |
467 | 467 | case 21: |
468 | 468 | if (in_array($this->shapeType,array(11,21)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
469 | - if (in_array($this->shapeType,array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
470 | - //Substitutes the value of the current point |
|
471 | - $this->SHPData = $point; |
|
472 | - break; |
|
473 | - case 3: |
|
469 | + if (in_array($this->shapeType,array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
470 | + //Substitutes the value of the current point |
|
471 | + $this->SHPData = $point; |
|
472 | + break; |
|
473 | + case 3: |
|
474 | 474 | case 5: |
475 | 475 | case 13: |
476 | 476 | case 15: |
477 | 477 | case 23: |
478 | 478 | case 25: |
479 | 479 | if (in_array($this->shapeType,array(13,15,23,25)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
480 | - if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
481 | - |
|
482 | - //Adds a new point to the selected part |
|
483 | - if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
484 | - if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
485 | - if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"]; |
|
486 | - if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"]; |
|
487 | - if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
488 | - if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
489 | - if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"]; |
|
490 | - if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
|
491 | - |
|
492 | - $this->SHPData["parts"][$partIndex]["points"][] = $point; |
|
493 | - |
|
494 | - $this->SHPData["numparts"] = count($this->SHPData["parts"]); |
|
495 | - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
496 | - break; |
|
497 | - case 8: |
|
480 | + if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
481 | + |
|
482 | + //Adds a new point to the selected part |
|
483 | + if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
484 | + if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
485 | + if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"]; |
|
486 | + if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"]; |
|
487 | + if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
488 | + if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
489 | + if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"]; |
|
490 | + if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
|
491 | + |
|
492 | + $this->SHPData["parts"][$partIndex]["points"][] = $point; |
|
493 | + |
|
494 | + $this->SHPData["numparts"] = count($this->SHPData["parts"]); |
|
495 | + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
496 | + break; |
|
497 | + case 8: |
|
498 | 498 | case 18: |
499 | 499 | case 28: |
500 | 500 | if (in_array($this->shapeType,array(18,28)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
501 | - if (in_array($this->shapeType,array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
502 | - |
|
503 | - //Adds a new point |
|
504 | - if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
505 | - if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
506 | - if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"]; |
|
507 | - if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"]; |
|
508 | - if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
509 | - if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
510 | - if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"]; |
|
511 | - if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
|
512 | - |
|
513 | - $this->SHPData["points"][] = $point; |
|
514 | - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
515 | - break; |
|
516 | - default: |
|
501 | + if (in_array($this->shapeType,array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
502 | + |
|
503 | + //Adds a new point |
|
504 | + if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
505 | + if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
506 | + if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"]; |
|
507 | + if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"]; |
|
508 | + if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
509 | + if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
510 | + if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"]; |
|
511 | + if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
|
512 | + |
|
513 | + $this->SHPData["points"][] = $point; |
|
514 | + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
515 | + break; |
|
516 | + default: |
|
517 | 517 | $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
518 | - break; |
|
518 | + break; |
|
519 | + } |
|
519 | 520 | } |
520 | - } |
|
521 | 521 | |
522 | - function deletePoint($pointIndex = 0, $partIndex = 0) { |
|
522 | + function deletePoint($pointIndex = 0, $partIndex = 0) { |
|
523 | 523 | switch ($this->shapeType) { |
524 | - case 0: |
|
524 | + case 0: |
|
525 | 525 | //Don't delete anything |
526 | 526 | break; |
527 | - case 1: |
|
527 | + case 1: |
|
528 | 528 | case 11: |
529 | 529 | case 21: |
530 | 530 | //Sets the value of the point to zero |
531 | 531 | $this->SHPData["x"] = 0.0; |
532 | - $this->SHPData["y"] = 0.0; |
|
533 | - if (in_array($this->shapeType,array(11,21))) $this->SHPData["m"] = 0.0; |
|
534 | - if (in_array($this->shapeType,array(11))) $this->SHPData["z"] = 0.0; |
|
535 | - break; |
|
536 | - case 3: |
|
532 | + $this->SHPData["y"] = 0.0; |
|
533 | + if (in_array($this->shapeType,array(11,21))) $this->SHPData["m"] = 0.0; |
|
534 | + if (in_array($this->shapeType,array(11))) $this->SHPData["z"] = 0.0; |
|
535 | + break; |
|
536 | + case 3: |
|
537 | 537 | case 5: |
538 | 538 | case 13: |
539 | 539 | case 15: |
@@ -542,107 +542,107 @@ discard block |
||
542 | 542 | //Deletes the point from the selected part, if exists |
543 | 543 | if (isset($this->SHPData["parts"][$partIndex]) && isset($this->SHPData["parts"][$partIndex]["points"][$pointIndex])) { |
544 | 544 | for ($i = $pointIndex; $i < (count($this->SHPData["parts"][$partIndex]["points"]) - 1); $i++) { |
545 | - $this->SHPData["parts"][$partIndex]["points"][$i] = $this->SHPData["parts"][$partIndex]["points"][$i + 1]; |
|
545 | + $this->SHPData["parts"][$partIndex]["points"][$i] = $this->SHPData["parts"][$partIndex]["points"][$i + 1]; |
|
546 | 546 | } |
547 | 547 | unset($this->SHPData["parts"][$partIndex]["points"][count($this->SHPData["parts"][$partIndex]["points"]) - 1]); |
548 | 548 | |
549 | 549 | $this->SHPData["numparts"] = count($this->SHPData["parts"]); |
550 | 550 | $this->SHPData["numpoints"]--; |
551 | - } |
|
552 | - break; |
|
553 | - case 8: |
|
551 | + } |
|
552 | + break; |
|
553 | + case 8: |
|
554 | 554 | case 18: |
555 | 555 | case 28: |
556 | 556 | //Deletes the point, if exists |
557 | 557 | if (isset($this->SHPData["points"][$pointIndex])) { |
558 | 558 | for ($i = $pointIndex; $i < (count($this->SHPData["points"]) - 1); $i++) { |
559 | - $this->SHPData["points"][$i] = $this->SHPData["points"][$i + 1]; |
|
559 | + $this->SHPData["points"][$i] = $this->SHPData["points"][$i + 1]; |
|
560 | 560 | } |
561 | 561 | unset($this->SHPData["points"][count($this->SHPData["points"]) - 1]); |
562 | 562 | |
563 | 563 | $this->SHPData["numpoints"]--; |
564 | - } |
|
565 | - break; |
|
566 | - default: |
|
564 | + } |
|
565 | + break; |
|
566 | + default: |
|
567 | 567 | $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
568 | - break; |
|
568 | + break; |
|
569 | + } |
|
569 | 570 | } |
570 | - } |
|
571 | 571 | |
572 | - function getContentLength() { |
|
572 | + function getContentLength() { |
|
573 | 573 | // The content length for a record is the length of the record contents section measured in 16-bit words. |
574 | 574 | // one coordinate makes 4 16-bit words (64 bit double) |
575 | 575 | switch ($this->shapeType) { |
576 | - case 0: |
|
576 | + case 0: |
|
577 | 577 | $result = 0; |
578 | - break; |
|
579 | - case 1: |
|
578 | + break; |
|
579 | + case 1: |
|
580 | 580 | $result = 10; |
581 | - break; |
|
582 | - case 21: |
|
581 | + break; |
|
582 | + case 21: |
|
583 | 583 | $result = 10 + 4; |
584 | - break; |
|
585 | - case 11: |
|
584 | + break; |
|
585 | + case 11: |
|
586 | 586 | $result = 10 + 8; |
587 | - break; |
|
588 | - case 3: |
|
587 | + break; |
|
588 | + case 3: |
|
589 | 589 | case 5: |
590 | 590 | $result = 22 + 2*count($this->SHPData["parts"]); |
591 | - for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
|
591 | + for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
|
592 | 592 | $result += 8*count($this->SHPData["parts"][$i]["points"]); |
593 | - } |
|
594 | - break; |
|
595 | - case 23: |
|
593 | + } |
|
594 | + break; |
|
595 | + case 23: |
|
596 | 596 | case 25: |
597 | 597 | $result = 22 + (2*4) + 2*count($this->SHPData["parts"]); |
598 | - for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
|
598 | + for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
|
599 | 599 | $result += (8+4)*count($this->SHPData["parts"][$i]["points"]); |
600 | - } |
|
601 | - break; |
|
602 | - case 13: |
|
600 | + } |
|
601 | + break; |
|
602 | + case 13: |
|
603 | 603 | case 15: |
604 | 604 | $result = 22 + (4*4) + 2*count($this->SHPData["parts"]); |
605 | - for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
|
605 | + for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
|
606 | 606 | $result += (8+8)*count($this->SHPData["parts"][$i]["points"]); |
607 | - } |
|
608 | - break; |
|
609 | - case 8: |
|
607 | + } |
|
608 | + break; |
|
609 | + case 8: |
|
610 | 610 | $result = 20 + 8*count($this->SHPData["points"]); |
611 | - break; |
|
612 | - case 28: |
|
611 | + break; |
|
612 | + case 28: |
|
613 | 613 | $result = 20 + (2*4) + (8+4)*count($this->SHPData["points"]); |
614 | - break; |
|
615 | - case 18: |
|
614 | + break; |
|
615 | + case 18: |
|
616 | 616 | $result = 20 + (4*4) + (8+8)*count($this->SHPData["points"]); |
617 | - break; |
|
618 | - default: |
|
617 | + break; |
|
618 | + default: |
|
619 | 619 | $result = false; |
620 | - $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
|
621 | - break; |
|
620 | + $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
|
621 | + break; |
|
622 | 622 | } |
623 | 623 | return $result; |
624 | - } |
|
624 | + } |
|
625 | 625 | |
626 | - function _loadDBFData() { |
|
626 | + function _loadDBFData() { |
|
627 | 627 | $this->DBFData = @dbase_get_record_with_names($this->DBFFile, $this->recordNumber); |
628 | 628 | unset($this->DBFData["deleted"]); |
629 | - } |
|
629 | + } |
|
630 | 630 | |
631 | - function _saveDBFData() { |
|
631 | + function _saveDBFData() { |
|
632 | 632 | unset($this->DBFData["deleted"]); |
633 | 633 | if ($this->recordNumber <= dbase_numrecords($this->DBFFile)) { |
634 | - if (!dbase_replace_record($this->DBFFile, array_values($this->DBFData), $this->recordNumber)) { |
|
635 | - $this->setError("I wasn't possible to update the information in the DBF file."); |
|
636 | - } |
|
634 | + if (!dbase_replace_record($this->DBFFile, array_values($this->DBFData), $this->recordNumber)) { |
|
635 | + $this->setError("I wasn't possible to update the information in the DBF file."); |
|
636 | + } |
|
637 | 637 | } else { |
638 | - if (!dbase_add_record($this->DBFFile, array_values($this->DBFData))) { |
|
639 | - $this->setError("I wasn't possible to add the information to the DBF file."); |
|
640 | - } |
|
638 | + if (!dbase_add_record($this->DBFFile, array_values($this->DBFData))) { |
|
639 | + $this->setError("I wasn't possible to add the information to the DBF file."); |
|
640 | + } |
|
641 | + } |
|
641 | 642 | } |
642 | - } |
|
643 | 643 | |
644 | - function setError($error) { |
|
644 | + function setError($error) { |
|
645 | 645 | $this->lastError = $error; |
646 | 646 | return false; |
647 | - } |
|
648 | - } |
|
647 | + } |
|
648 | + } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | - function _loadMultiPointMZRecord( $type ) { |
|
278 | + function _loadMultiPointMZRecord($type) { |
|
279 | 279 | |
280 | 280 | $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); |
281 | 281 | $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
311 | - function _saveMultiPointMZRecord( $type ) { |
|
311 | + function _saveMultiPointMZRecord($type) { |
|
312 | 312 | |
313 | 313 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
314 | 314 | |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | } |
359 | 359 | } |
360 | 360 | |
361 | - fseek($this->SHPFile, $firstIndex + ($readPoints*16)); |
|
361 | + fseek($this->SHPFile, $firstIndex + ($readPoints * 16)); |
|
362 | 362 | } |
363 | 363 | |
364 | - function _loadPolyLineMZRecord( $type ) { |
|
364 | + function _loadPolyLineMZRecord($type) { |
|
365 | 365 | |
366 | 366 | $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); |
367 | 367 | $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8)); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | - fseek($this->SHPFile, $firstIndex + ($readPoints*24)); |
|
379 | + fseek($this->SHPFile, $firstIndex + ($readPoints * 24)); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | function _loadPolyLineMRecord() { |
@@ -398,10 +398,10 @@ discard block |
||
398 | 398 | fwrite($this->SHPFile, pack("VV", $this->SHPData["numparts"], $this->SHPData["numpoints"])); |
399 | 399 | |
400 | 400 | for ($i = 0; $i < $this->SHPData["numparts"]; $i++) { |
401 | - fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i])-1)); |
|
401 | + fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i]) - 1)); |
|
402 | 402 | } |
403 | 403 | |
404 | - foreach ($this->SHPData["parts"] as $partData){ |
|
404 | + foreach ($this->SHPData["parts"] as $partData) { |
|
405 | 405 | reset($partData["points"]); |
406 | 406 | while (list($pointIndex, $pointData) = each($partData["points"])) { |
407 | 407 | $this->_savePoint($pointData); |
@@ -409,10 +409,10 @@ discard block |
||
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | - function _savePolyLineMZRecord( $type ) { |
|
412 | + function _savePolyLineMZRecord($type) { |
|
413 | 413 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
414 | 414 | |
415 | - foreach ($this->SHPData["parts"] as $partData){ |
|
415 | + foreach ($this->SHPData["parts"] as $partData) { |
|
416 | 416 | reset($partData["points"]); |
417 | 417 | while (list($pointIndex, $pointData) = each($partData["points"])) { |
418 | 418 | fwrite($this->SHPFile, Util::packDouble($pointData[$type])); |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | case 1: |
466 | 466 | case 11: |
467 | 467 | case 21: |
468 | - if (in_array($this->shapeType,array(11,21)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
469 | - if (in_array($this->shapeType,array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
468 | + if (in_array($this->shapeType, array(11, 21)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
469 | + if (in_array($this->shapeType, array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
470 | 470 | //Substitutes the value of the current point |
471 | 471 | $this->SHPData = $point; |
472 | 472 | break; |
@@ -476,8 +476,8 @@ discard block |
||
476 | 476 | case 15: |
477 | 477 | case 23: |
478 | 478 | case 25: |
479 | - if (in_array($this->shapeType,array(13,15,23,25)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
480 | - if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
479 | + if (in_array($this->shapeType, array(13, 15, 23, 25)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
480 | + if (in_array($this->shapeType, array(13, 15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
481 | 481 | |
482 | 482 | //Adds a new point to the selected part |
483 | 483 | if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
@@ -492,13 +492,13 @@ discard block |
||
492 | 492 | $this->SHPData["parts"][$partIndex]["points"][] = $point; |
493 | 493 | |
494 | 494 | $this->SHPData["numparts"] = count($this->SHPData["parts"]); |
495 | - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
495 | + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"]) ? $this->SHPData["numpoints"] : 0); |
|
496 | 496 | break; |
497 | 497 | case 8: |
498 | 498 | case 18: |
499 | 499 | case 28: |
500 | - if (in_array($this->shapeType,array(18,28)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
501 | - if (in_array($this->shapeType,array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
500 | + if (in_array($this->shapeType, array(18, 28)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
501 | + if (in_array($this->shapeType, array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
502 | 502 | |
503 | 503 | //Adds a new point |
504 | 504 | if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
512 | 512 | |
513 | 513 | $this->SHPData["points"][] = $point; |
514 | - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
514 | + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"]) ? $this->SHPData["numpoints"] : 0); |
|
515 | 515 | break; |
516 | 516 | default: |
517 | 517 | $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
@@ -530,8 +530,8 @@ discard block |
||
530 | 530 | //Sets the value of the point to zero |
531 | 531 | $this->SHPData["x"] = 0.0; |
532 | 532 | $this->SHPData["y"] = 0.0; |
533 | - if (in_array($this->shapeType,array(11,21))) $this->SHPData["m"] = 0.0; |
|
534 | - if (in_array($this->shapeType,array(11))) $this->SHPData["z"] = 0.0; |
|
533 | + if (in_array($this->shapeType, array(11, 21))) $this->SHPData["m"] = 0.0; |
|
534 | + if (in_array($this->shapeType, array(11))) $this->SHPData["z"] = 0.0; |
|
535 | 535 | break; |
536 | 536 | case 3: |
537 | 537 | case 5: |
@@ -587,33 +587,33 @@ discard block |
||
587 | 587 | break; |
588 | 588 | case 3: |
589 | 589 | case 5: |
590 | - $result = 22 + 2*count($this->SHPData["parts"]); |
|
590 | + $result = 22 + 2 * count($this->SHPData["parts"]); |
|
591 | 591 | for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
592 | - $result += 8*count($this->SHPData["parts"][$i]["points"]); |
|
592 | + $result += 8 * count($this->SHPData["parts"][$i]["points"]); |
|
593 | 593 | } |
594 | 594 | break; |
595 | 595 | case 23: |
596 | 596 | case 25: |
597 | - $result = 22 + (2*4) + 2*count($this->SHPData["parts"]); |
|
597 | + $result = 22 + (2 * 4) + 2 * count($this->SHPData["parts"]); |
|
598 | 598 | for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
599 | - $result += (8+4)*count($this->SHPData["parts"][$i]["points"]); |
|
599 | + $result += (8 + 4) * count($this->SHPData["parts"][$i]["points"]); |
|
600 | 600 | } |
601 | 601 | break; |
602 | 602 | case 13: |
603 | 603 | case 15: |
604 | - $result = 22 + (4*4) + 2*count($this->SHPData["parts"]); |
|
604 | + $result = 22 + (4 * 4) + 2 * count($this->SHPData["parts"]); |
|
605 | 605 | for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
606 | - $result += (8+8)*count($this->SHPData["parts"][$i]["points"]); |
|
606 | + $result += (8 + 8) * count($this->SHPData["parts"][$i]["points"]); |
|
607 | 607 | } |
608 | 608 | break; |
609 | 609 | case 8: |
610 | - $result = 20 + 8*count($this->SHPData["points"]); |
|
610 | + $result = 20 + 8 * count($this->SHPData["points"]); |
|
611 | 611 | break; |
612 | 612 | case 28: |
613 | - $result = 20 + (2*4) + (8+4)*count($this->SHPData["points"]); |
|
613 | + $result = 20 + (2 * 4) + (8 + 4) * count($this->SHPData["points"]); |
|
614 | 614 | break; |
615 | 615 | case 18: |
616 | - $result = 20 + (4*4) + (8+8)*count($this->SHPData["points"]); |
|
616 | + $result = 20 + (4 * 4) + (8 + 8) * count($this->SHPData["points"]); |
|
617 | 617 | break; |
618 | 618 | default: |
619 | 619 | $result = false; |
@@ -465,8 +465,14 @@ discard block |
||
465 | 465 | case 1: |
466 | 466 | case 11: |
467 | 467 | case 21: |
468 | - if (in_array($this->shapeType,array(11,21)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
469 | - if (in_array($this->shapeType,array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
468 | + if (in_array($this->shapeType,array(11,21)) && !isset($point["m"])) { |
|
469 | + $point["m"] = 0.0; |
|
470 | + } |
|
471 | + // no_value |
|
472 | + if (in_array($this->shapeType,array(11)) && !isset($point["z"])) { |
|
473 | + $point["z"] = 0.0; |
|
474 | + } |
|
475 | + // no_value |
|
470 | 476 | //Substitutes the value of the current point |
471 | 477 | $this->SHPData = $point; |
472 | 478 | break; |
@@ -476,18 +482,40 @@ discard block |
||
476 | 482 | case 15: |
477 | 483 | case 23: |
478 | 484 | case 25: |
479 | - if (in_array($this->shapeType,array(13,15,23,25)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
480 | - if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
485 | + if (in_array($this->shapeType,array(13,15,23,25)) && !isset($point["m"])) { |
|
486 | + $point["m"] = 0.0; |
|
487 | + } |
|
488 | + // no_value |
|
489 | + if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) { |
|
490 | + $point["z"] = 0.0; |
|
491 | + } |
|
492 | + // no_value |
|
481 | 493 | |
482 | 494 | //Adds a new point to the selected part |
483 | - if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
484 | - if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
485 | - if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"]; |
|
486 | - if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"]; |
|
487 | - if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
488 | - if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
489 | - if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"]; |
|
490 | - if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
|
495 | + if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) { |
|
496 | + $this->SHPData["xmin"] = $point["x"]; |
|
497 | + } |
|
498 | + if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) { |
|
499 | + $this->SHPData["ymin"] = $point["y"]; |
|
500 | + } |
|
501 | + if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) { |
|
502 | + $this->SHPData["mmin"] = $point["m"]; |
|
503 | + } |
|
504 | + if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) { |
|
505 | + $this->SHPData["zmin"] = $point["z"]; |
|
506 | + } |
|
507 | + if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) { |
|
508 | + $this->SHPData["xmax"] = $point["x"]; |
|
509 | + } |
|
510 | + if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) { |
|
511 | + $this->SHPData["ymax"] = $point["y"]; |
|
512 | + } |
|
513 | + if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) { |
|
514 | + $this->SHPData["mmax"] = $point["m"]; |
|
515 | + } |
|
516 | + if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) { |
|
517 | + $this->SHPData["zmax"] = $point["z"]; |
|
518 | + } |
|
491 | 519 | |
492 | 520 | $this->SHPData["parts"][$partIndex]["points"][] = $point; |
493 | 521 | |
@@ -497,18 +525,40 @@ discard block |
||
497 | 525 | case 8: |
498 | 526 | case 18: |
499 | 527 | case 28: |
500 | - if (in_array($this->shapeType,array(18,28)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
501 | - if (in_array($this->shapeType,array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
528 | + if (in_array($this->shapeType,array(18,28)) && !isset($point["m"])) { |
|
529 | + $point["m"] = 0.0; |
|
530 | + } |
|
531 | + // no_value |
|
532 | + if (in_array($this->shapeType,array(18)) && !isset($point["z"])) { |
|
533 | + $point["z"] = 0.0; |
|
534 | + } |
|
535 | + // no_value |
|
502 | 536 | |
503 | 537 | //Adds a new point |
504 | - if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
505 | - if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
506 | - if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"]; |
|
507 | - if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"]; |
|
508 | - if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
509 | - if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
510 | - if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"]; |
|
511 | - if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
|
538 | + if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) { |
|
539 | + $this->SHPData["xmin"] = $point["x"]; |
|
540 | + } |
|
541 | + if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) { |
|
542 | + $this->SHPData["ymin"] = $point["y"]; |
|
543 | + } |
|
544 | + if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) { |
|
545 | + $this->SHPData["mmin"] = $point["m"]; |
|
546 | + } |
|
547 | + if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) { |
|
548 | + $this->SHPData["zmin"] = $point["z"]; |
|
549 | + } |
|
550 | + if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) { |
|
551 | + $this->SHPData["xmax"] = $point["x"]; |
|
552 | + } |
|
553 | + if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) { |
|
554 | + $this->SHPData["ymax"] = $point["y"]; |
|
555 | + } |
|
556 | + if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) { |
|
557 | + $this->SHPData["mmax"] = $point["m"]; |
|
558 | + } |
|
559 | + if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) { |
|
560 | + $this->SHPData["zmax"] = $point["z"]; |
|
561 | + } |
|
512 | 562 | |
513 | 563 | $this->SHPData["points"][] = $point; |
514 | 564 | $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
@@ -530,8 +580,12 @@ discard block |
||
530 | 580 | //Sets the value of the point to zero |
531 | 581 | $this->SHPData["x"] = 0.0; |
532 | 582 | $this->SHPData["y"] = 0.0; |
533 | - if (in_array($this->shapeType,array(11,21))) $this->SHPData["m"] = 0.0; |
|
534 | - if (in_array($this->shapeType,array(11))) $this->SHPData["z"] = 0.0; |
|
583 | + if (in_array($this->shapeType,array(11,21))) { |
|
584 | + $this->SHPData["m"] = 0.0; |
|
585 | + } |
|
586 | + if (in_array($this->shapeType,array(11))) { |
|
587 | + $this->SHPData["z"] = 0.0; |
|
588 | + } |
|
535 | 589 | break; |
536 | 590 | case 3: |
537 | 591 | case 5: |
@@ -31,27 +31,27 @@ discard block |
||
31 | 31 | namespace ShapeFile; |
32 | 32 | |
33 | 33 | class Util { |
34 | - public static function loadData($type, $data) { |
|
35 | - if (!$data) return $data; |
|
36 | - $tmp = unpack($type, $data); |
|
37 | - return current($tmp); |
|
38 | - } |
|
34 | + public static function loadData($type, $data) { |
|
35 | + if (!$data) return $data; |
|
36 | + $tmp = unpack($type, $data); |
|
37 | + return current($tmp); |
|
38 | + } |
|
39 | 39 | |
40 | - public static function swap($binValue) { |
|
41 | - $result = $binValue{strlen($binValue) - 1}; |
|
42 | - for($i = strlen($binValue) - 2; $i >= 0 ; $i--) { |
|
40 | + public static function swap($binValue) { |
|
41 | + $result = $binValue{strlen($binValue) - 1}; |
|
42 | + for($i = strlen($binValue) - 2; $i >= 0 ; $i--) { |
|
43 | 43 | $result .= $binValue{$i}; |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - return $result; |
|
47 | - } |
|
46 | + return $result; |
|
47 | + } |
|
48 | 48 | |
49 | - public static function packDouble($value, $mode = 'LE') { |
|
50 | - $value = (double)$value; |
|
51 | - $bin = pack("d", $value); |
|
49 | + public static function packDouble($value, $mode = 'LE') { |
|
50 | + $value = (double)$value; |
|
51 | + $bin = pack("d", $value); |
|
52 | 52 | |
53 | - //We test if the conversion of an integer (1) is done as LE or BE by default |
|
54 | - switch (pack ('L', 1)) { |
|
53 | + //We test if the conversion of an integer (1) is done as LE or BE by default |
|
54 | + switch (pack ('L', 1)) { |
|
55 | 55 | case pack ('V', 1): //Little Endian |
56 | 56 | $result = ($mode == 'LE') ? $bin : self::swap($bin); |
57 | 57 | break; |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | break; |
61 | 61 | default: //Some other thing, we just return false |
62 | 62 | $result = FALSE; |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - return $result; |
|
66 | - } |
|
65 | + return $result; |
|
66 | + } |
|
67 | 67 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | public static function swap($binValue) { |
41 | 41 | $result = $binValue{strlen($binValue) - 1}; |
42 | - for($i = strlen($binValue) - 2; $i >= 0 ; $i--) { |
|
42 | + for ($i = strlen($binValue) - 2; $i >= 0; $i--) { |
|
43 | 43 | $result .= $binValue{$i}; |
44 | 44 | } |
45 | 45 | |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | public static function packDouble($value, $mode = 'LE') { |
50 | - $value = (double)$value; |
|
50 | + $value = (double) $value; |
|
51 | 51 | $bin = pack("d", $value); |
52 | 52 | |
53 | 53 | //We test if the conversion of an integer (1) is done as LE or BE by default |
54 | - switch (pack ('L', 1)) { |
|
55 | - case pack ('V', 1): //Little Endian |
|
54 | + switch (pack('L', 1)) { |
|
55 | + case pack('V', 1): //Little Endian |
|
56 | 56 | $result = ($mode == 'LE') ? $bin : self::swap($bin); |
57 | 57 | break; |
58 | - case pack ('N', 1): //Big Endian |
|
58 | + case pack('N', 1): //Big Endian |
|
59 | 59 | $result = ($mode == 'BE') ? $bin : self::swap($bin); |
60 | 60 | break; |
61 | 61 | default: //Some other thing, we just return false |
@@ -32,7 +32,9 @@ |
||
32 | 32 | |
33 | 33 | class Util { |
34 | 34 | public static function loadData($type, $data) { |
35 | - if (!$data) return $data; |
|
35 | + if (!$data) { |
|
36 | + return $data; |
|
37 | + } |
|
36 | 38 | $tmp = unpack($type, $data); |
37 | 39 | return current($tmp); |
38 | 40 | } |