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