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