@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | $point_coords = unpack("d*", fread($mem,$this->dimension*8)); |
89 | 89 | if (!empty($point_coords)) { |
90 | 90 | return new Point($point_coords[1],$point_coords[2]); |
91 | - } |
|
92 | - else { |
|
91 | + } else { |
|
93 | 92 | return new Point(); // EMPTY point |
94 | 93 | } |
95 | 94 | } |
@@ -99,7 +98,9 @@ discard block |
||
99 | 98 | $line_length = unpack('L',fread($mem,4)); |
100 | 99 | |
101 | 100 | // Return an empty linestring if there is no line-length |
102 | - if (!$line_length[1]) return new LineString(); |
|
101 | + if (!$line_length[1]) { |
|
102 | + return new LineString(); |
|
103 | + } |
|
103 | 104 | |
104 | 105 | // Read the nubmer of points x2 (each point is two coords) into decimal-floats |
105 | 106 | $line_coords = unpack('d*', fread($mem,$line_length[1]*$this->dimension*8)); |
@@ -195,8 +196,7 @@ discard block |
||
195 | 196 | if ($write_as_hex) { |
196 | 197 | $unpacked = unpack('H*',$wkb); |
197 | 198 | return $unpacked[1]; |
198 | - } |
|
199 | - else { |
|
199 | + } else { |
|
200 | 200 | return $wkb; |
201 | 201 | } |
202 | 202 | } |
@@ -75,8 +75,7 @@ discard block |
||
75 | 75 | $ll = $this->decode($hash); |
76 | 76 | if (!$as_grid) { |
77 | 77 | return new Point($ll['medlon'], $ll['medlat']); |
78 | - } |
|
79 | - else { |
|
78 | + } else { |
|
80 | 79 | return new Polygon(array( |
81 | 80 | new LineString(array( |
82 | 81 | new Point($ll['minlon'], $ll['maxlat']), |
@@ -96,12 +95,13 @@ discard block |
||
96 | 95 | * @see GeoAdapter::write() |
97 | 96 | */ |
98 | 97 | public function write(Geometry $geometry, $precision = NULL){ |
99 | - if ($geometry->isEmpty()) return ''; |
|
98 | + if ($geometry->isEmpty()) { |
|
99 | + return ''; |
|
100 | + } |
|
100 | 101 | |
101 | 102 | if($geometry->geometryType() === 'Point'){ |
102 | 103 | return $this->encodePoint($geometry, $precision); |
103 | - } |
|
104 | - else { |
|
104 | + } else { |
|
105 | 105 | // The geohash is the hash grid ID that fits the envelope |
106 | 106 | $envelope = $geometry->envelope(); |
107 | 107 | $geohashes = array(); |
@@ -194,19 +194,59 @@ discard block |
||
194 | 194 | for($i=0,$c=strlen($hash);$i<$c;$i++) { |
195 | 195 | $v = strpos($this->table,$hash[$i]); |
196 | 196 | if(1&$i) { |
197 | - if(16&$v)$minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
198 | - if(8&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
199 | - if(4&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
200 | - if(2&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
201 | - if(1&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
197 | + if(16&$v) { |
|
198 | + $minlat = ($minlat+$maxlat)/2; |
|
199 | + } else { |
|
200 | + $maxlat = ($minlat+$maxlat)/2; |
|
201 | + } |
|
202 | + if(8&$v) { |
|
203 | + $minlon = ($minlon+$maxlon)/2; |
|
204 | + } else { |
|
205 | + $maxlon = ($minlon+$maxlon)/2; |
|
206 | + } |
|
207 | + if(4&$v) { |
|
208 | + $minlat = ($minlat+$maxlat)/2; |
|
209 | + } else { |
|
210 | + $maxlat = ($minlat+$maxlat)/2; |
|
211 | + } |
|
212 | + if(2&$v) { |
|
213 | + $minlon = ($minlon+$maxlon)/2; |
|
214 | + } else { |
|
215 | + $maxlon = ($minlon+$maxlon)/2; |
|
216 | + } |
|
217 | + if(1&$v) { |
|
218 | + $minlat = ($minlat+$maxlat)/2; |
|
219 | + } else { |
|
220 | + $maxlat = ($minlat+$maxlat)/2; |
|
221 | + } |
|
202 | 222 | $latE /= 8; |
203 | 223 | $lonE /= 4; |
204 | 224 | } else { |
205 | - if(16&$v)$minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
206 | - if(8&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
207 | - if(4&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
208 | - if(2&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
209 | - if(1&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
225 | + if(16&$v) { |
|
226 | + $minlon = ($minlon+$maxlon)/2; |
|
227 | + } else { |
|
228 | + $maxlon = ($minlon+$maxlon)/2; |
|
229 | + } |
|
230 | + if(8&$v) { |
|
231 | + $minlat = ($minlat+$maxlat)/2; |
|
232 | + } else { |
|
233 | + $maxlat = ($minlat+$maxlat)/2; |
|
234 | + } |
|
235 | + if(4&$v) { |
|
236 | + $minlon = ($minlon+$maxlon)/2; |
|
237 | + } else { |
|
238 | + $maxlon = ($minlon+$maxlon)/2; |
|
239 | + } |
|
240 | + if(2&$v) { |
|
241 | + $minlat = ($minlat+$maxlat)/2; |
|
242 | + } else { |
|
243 | + $maxlat = ($minlat+$maxlat)/2; |
|
244 | + } |
|
245 | + if(1&$v) { |
|
246 | + $minlon = ($minlon+$maxlon)/2; |
|
247 | + } else { |
|
248 | + $maxlon = ($minlon+$maxlon)/2; |
|
249 | + } |
|
210 | 250 | $latE /= 4; |
211 | 251 | $lonE /= 8; |
212 | 252 | } |
@@ -21,8 +21,7 @@ discard block |
||
21 | 21 | $wkt = $parts[1]; |
22 | 22 | $eparts = explode('=',$parts[0]); |
23 | 23 | $srid = $eparts[1]; |
24 | - } |
|
25 | - else { |
|
24 | + } else { |
|
26 | 25 | $srid = NULL; |
27 | 26 | } |
28 | 27 | |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | $geom = geoPHP::geosToGeometry($reader->read($wkt)); |
34 | 33 | $geom->setSRID($srid); |
35 | 34 | return $geom; |
36 | - } |
|
37 | - else { |
|
35 | + } else { |
|
38 | 36 | return geoPHP::geosToGeometry($reader->read($wkt)); |
39 | 37 | } |
40 | 38 | } |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | $geom = $this->$method($data_string); |
53 | 51 | $geom->setSRID($srid); |
54 | 52 | return $geom; |
55 | - } |
|
56 | - else { |
|
53 | + } else { |
|
57 | 54 | return $this->$method($data_string); |
58 | 55 | } |
59 | 56 | |
@@ -65,7 +62,9 @@ discard block |
||
65 | 62 | $data_string = $this->trimParens($data_string); |
66 | 63 | |
67 | 64 | // If it's marked as empty, then return an empty point |
68 | - if ($data_string == 'EMPTY') return new Point(); |
|
65 | + if ($data_string == 'EMPTY') { |
|
66 | + return new Point(); |
|
67 | + } |
|
69 | 68 | |
70 | 69 | $parts = explode(' ',$data_string); |
71 | 70 | return new Point($parts[0], $parts[1]); |
@@ -75,7 +74,9 @@ discard block |
||
75 | 74 | $data_string = $this->trimParens($data_string); |
76 | 75 | |
77 | 76 | // If it's marked as empty, then return an empty line |
78 | - if ($data_string == 'EMPTY') return new LineString(); |
|
77 | + if ($data_string == 'EMPTY') { |
|
78 | + return new LineString(); |
|
79 | + } |
|
79 | 80 | |
80 | 81 | $parts = explode(',',$data_string); |
81 | 82 | $points = array(); |
@@ -89,13 +90,19 @@ discard block |
||
89 | 90 | $data_string = $this->trimParens($data_string); |
90 | 91 | |
91 | 92 | // If it's marked as empty, then return an empty polygon |
92 | - if ($data_string == 'EMPTY') return new Polygon(); |
|
93 | + if ($data_string == 'EMPTY') { |
|
94 | + return new Polygon(); |
|
95 | + } |
|
93 | 96 | |
94 | 97 | $parts = explode('),(',$data_string); |
95 | 98 | $lines = array(); |
96 | 99 | foreach ($parts as $part) { |
97 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
98 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
100 | + if (!$this->beginsWith($part,'(')) { |
|
101 | + $part = '(' . $part; |
|
102 | + } |
|
103 | + if (!$this->endsWith($part,')')) { |
|
104 | + $part = $part . ')'; |
|
105 | + } |
|
99 | 106 | $lines[] = $this->parseLineString($part); |
100 | 107 | } |
101 | 108 | return new Polygon($lines); |
@@ -105,7 +112,9 @@ discard block |
||
105 | 112 | $data_string = $this->trimParens($data_string); |
106 | 113 | |
107 | 114 | // If it's marked as empty, then return an empty MutiPoint |
108 | - if ($data_string == 'EMPTY') return new MultiPoint(); |
|
115 | + if ($data_string == 'EMPTY') { |
|
116 | + return new MultiPoint(); |
|
117 | + } |
|
109 | 118 | |
110 | 119 | $parts = explode(',',$data_string); |
111 | 120 | $points = array(); |
@@ -119,14 +128,20 @@ discard block |
||
119 | 128 | $data_string = $this->trimParens($data_string); |
120 | 129 | |
121 | 130 | // If it's marked as empty, then return an empty multi-linestring |
122 | - if ($data_string == 'EMPTY') return new MultiLineString(); |
|
131 | + if ($data_string == 'EMPTY') { |
|
132 | + return new MultiLineString(); |
|
133 | + } |
|
123 | 134 | |
124 | 135 | $parts = explode('),(',$data_string); |
125 | 136 | $lines = array(); |
126 | 137 | foreach ($parts as $part) { |
127 | 138 | // Repair the string if the explode broke it |
128 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
129 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
139 | + if (!$this->beginsWith($part,'(')) { |
|
140 | + $part = '(' . $part; |
|
141 | + } |
|
142 | + if (!$this->endsWith($part,')')) { |
|
143 | + $part = $part . ')'; |
|
144 | + } |
|
130 | 145 | $lines[] = $this->parseLineString($part); |
131 | 146 | } |
132 | 147 | return new MultiLineString($lines); |
@@ -136,14 +151,20 @@ discard block |
||
136 | 151 | $data_string = $this->trimParens($data_string); |
137 | 152 | |
138 | 153 | // If it's marked as empty, then return an empty multi-polygon |
139 | - if ($data_string == 'EMPTY') return new MultiPolygon(); |
|
154 | + if ($data_string == 'EMPTY') { |
|
155 | + return new MultiPolygon(); |
|
156 | + } |
|
140 | 157 | |
141 | 158 | $parts = explode(')),((',$data_string); |
142 | 159 | $polys = array(); |
143 | 160 | foreach ($parts as $part) { |
144 | 161 | // Repair the string if the explode broke it |
145 | - if (!$this->beginsWith($part,'((')) $part = '((' . $part; |
|
146 | - if (!$this->endsWith($part,'))')) $part = $part . '))'; |
|
162 | + if (!$this->beginsWith($part,'((')) { |
|
163 | + $part = '((' . $part; |
|
164 | + } |
|
165 | + if (!$this->endsWith($part,'))')) { |
|
166 | + $part = $part . '))'; |
|
167 | + } |
|
147 | 168 | $polys[] = $this->parsePolygon($part); |
148 | 169 | } |
149 | 170 | return new MultiPolygon($polys); |
@@ -153,7 +174,9 @@ discard block |
||
153 | 174 | $data_string = $this->trimParens($data_string); |
154 | 175 | |
155 | 176 | // If it's marked as empty, then return an empty geom-collection |
156 | - if ($data_string == 'EMPTY') return new GeometryCollection(); |
|
177 | + if ($data_string == 'EMPTY') { |
|
178 | + return new GeometryCollection(); |
|
179 | + } |
|
157 | 180 | |
158 | 181 | $geometries = array(); |
159 | 182 | $matches = array(); |
@@ -173,8 +196,9 @@ discard block |
||
173 | 196 | return substr($wkt, $first_paren); |
174 | 197 | } elseif (strstr($wkt,'EMPTY')) { |
175 | 198 | return 'EMPTY'; |
176 | - } else |
|
177 | - return FALSE; |
|
199 | + } else { |
|
200 | + return FALSE; |
|
201 | + } |
|
178 | 202 | } |
179 | 203 | |
180 | 204 | /** |
@@ -186,18 +210,25 @@ discard block |
||
186 | 210 | // We want to only strip off one set of parenthesis |
187 | 211 | if ($this->beginsWith($str, '(')) { |
188 | 212 | return substr($str,1,-1); |
213 | + } else { |
|
214 | + return $str; |
|
189 | 215 | } |
190 | - else return $str; |
|
191 | 216 | } |
192 | 217 | |
193 | 218 | protected function beginsWith($str, $char) { |
194 | - if (substr($str,0,strlen($char)) == $char) return TRUE; |
|
195 | - else return FALSE; |
|
219 | + if (substr($str,0,strlen($char)) == $char) { |
|
220 | + return TRUE; |
|
221 | + } else { |
|
222 | + return FALSE; |
|
223 | + } |
|
196 | 224 | } |
197 | 225 | |
198 | 226 | protected function endsWith($str, $char) { |
199 | - if (substr($str,(0 - strlen($char))) == $char) return TRUE; |
|
200 | - else return FALSE; |
|
227 | + if (substr($str,(0 - strlen($char))) == $char) { |
|
228 | + return TRUE; |
|
229 | + } else { |
|
230 | + return FALSE; |
|
231 | + } |
|
201 | 232 | } |
202 | 233 | |
203 | 234 | /** |
@@ -217,8 +248,7 @@ discard block |
||
217 | 248 | |
218 | 249 | if ($geometry->isEmpty()) { |
219 | 250 | return strtoupper($geometry->geometryType()).' EMPTY'; |
220 | - } |
|
221 | - else if ($data = $this->extractData($geometry)) { |
|
251 | + } else if ($data = $this->extractData($geometry)) { |
|
222 | 252 | return strtoupper($geometry->geometryType()).' ('.$data.')'; |
223 | 253 | } |
224 | 254 | } |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | $base_info = unpack("corder/ctype/cz/cm/cs", fread($mem, 5)); |
25 | 25 | if ($base_info['s']) { |
26 | 26 | $srid = current(unpack("Lsrid", fread($mem, 4))); |
27 | - } |
|
28 | - else { |
|
27 | + } else { |
|
29 | 28 | $srid = NULL; |
30 | 29 | } |
31 | 30 | fclose($mem); |
@@ -87,8 +86,7 @@ discard block |
||
87 | 86 | if ($write_as_hex) { |
88 | 87 | $unpacked = unpack('H*',$wkb); |
89 | 88 | return $unpacked[1]; |
90 | - } |
|
91 | - else { |
|
89 | + } else { |
|
92 | 90 | return $wkb; |
93 | 91 | } |
94 | 92 | } |
@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | - } |
|
92 | - else { |
|
91 | + } else { |
|
93 | 92 | // The document does not have a placemark, try to create a valid geometry from the root element |
94 | 93 | $node_name = $this->xmlobj->documentElement->nodeName == 'multigeometry' ? 'geometrycollection' : $this->xmlobj->documentElement->nodeName; |
95 | 94 | if (array_key_exists($node_name, $geom_types)) { |
@@ -116,8 +115,7 @@ discard block |
||
116 | 115 | $coordinates = $this->_extractCoordinates($xml); |
117 | 116 | if (!empty($coordinates)) { |
118 | 117 | return new Point($coordinates[0][0],$coordinates[0][1]); |
119 | - } |
|
120 | - else { |
|
118 | + } else { |
|
121 | 119 | return new Point(); |
122 | 120 | } |
123 | 121 | } |
@@ -232,7 +230,9 @@ discard block |
||
232 | 230 | $str .= '<'.$this->nss.'coordinates>'; |
233 | 231 | $i=0; |
234 | 232 | foreach ($geom->getComponents() as $comp) { |
235 | - if ($i != 0) $str .= ' '; |
|
233 | + if ($i != 0) { |
|
234 | + $str .= ' '; |
|
235 | + } |
|
236 | 236 | $str .= $comp->getX() .','. $comp->getY(); |
237 | 237 | $i++; |
238 | 238 | } |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | if (!$type) { |
53 | 53 | // If the user is trying to load a Geometry from a Geometry... Just pass it back |
54 | 54 | if (is_object($data)) { |
55 | - if ($data instanceOf Geometry) return $data; |
|
55 | + if ($data instanceOf Geometry) { |
|
56 | + return $data; |
|
57 | + } |
|
56 | 58 | } |
57 | 59 | |
58 | 60 | $detected = geoPHP::detectFormat($data); |
@@ -119,7 +121,9 @@ discard block |
||
119 | 121 | |
120 | 122 | static function geosInstalled($force = NULL) { |
121 | 123 | static $geos_installed = NULL; |
122 | - if ($force !== NULL) $geos_installed = $force; |
|
124 | + if ($force !== NULL) { |
|
125 | + $geos_installed = $force; |
|
126 | + } |
|
123 | 127 | if ($geos_installed !== NULL) { |
124 | 128 | return $geos_installed; |
125 | 129 | } |
@@ -147,8 +151,12 @@ discard block |
||
147 | 151 | static function geometryReduce($geometry) { |
148 | 152 | // If it's an array of one, then just parse the one |
149 | 153 | if (is_array($geometry)) { |
150 | - if (empty($geometry)) return FALSE; |
|
151 | - if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
154 | + if (empty($geometry)) { |
|
155 | + return FALSE; |
|
156 | + } |
|
157 | + if (count($geometry) == 1) { |
|
158 | + return geoPHP::geometryReduce(array_shift($geometry)); |
|
159 | + } |
|
152 | 160 | } |
153 | 161 | |
154 | 162 | // If the geometry cannot even theoretically be reduced more, then pass it back |
@@ -167,8 +175,7 @@ discard block |
||
167 | 175 | $components = $geometry->getComponents(); |
168 | 176 | if (count($components) == 1) { |
169 | 177 | return $components[0]; |
170 | - } |
|
171 | - else { |
|
178 | + } else { |
|
172 | 179 | return $geometry; |
173 | 180 | } |
174 | 181 | } |
@@ -191,8 +198,7 @@ discard block |
||
191 | 198 | $geometries[] = $component; |
192 | 199 | $geom_types[] = $component->geometryType(); |
193 | 200 | } |
194 | - } |
|
195 | - else { |
|
201 | + } else { |
|
196 | 202 | $geometries[] = $item; |
197 | 203 | $geom_types[] = $item->geometryType(); |
198 | 204 | } |
@@ -208,13 +214,11 @@ discard block |
||
208 | 214 | if (count($geom_types) == 1) { |
209 | 215 | if (count($geometries) == 1) { |
210 | 216 | return $geometries[0]; |
211 | - } |
|
212 | - else { |
|
217 | + } else { |
|
213 | 218 | $class = 'Multi'.$geom_types[0]; |
214 | 219 | return new $class($geometries); |
215 | 220 | } |
216 | - } |
|
217 | - else { |
|
221 | + } else { |
|
218 | 222 | return new GeometryCollection($geometries); |
219 | 223 | } |
220 | 224 | } |
@@ -229,7 +233,9 @@ discard block |
||
229 | 233 | $bytes = unpack("c*", fread($mem, 11)); |
230 | 234 | |
231 | 235 | // If bytes is empty, then we were passed empty input |
232 | - if (empty($bytes)) return FALSE; |
|
236 | + if (empty($bytes)) { |
|
237 | + return FALSE; |
|
238 | + } |
|
233 | 239 | |
234 | 240 | // First char is a tab, space or carriage-return. trim it and try again |
235 | 241 | if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) { |
@@ -240,8 +246,11 @@ discard block |
||
240 | 246 | // Detect WKB or EWKB -- first byte is 1 (little endian indicator) |
241 | 247 | if ($bytes[1] == 1) { |
242 | 248 | // If SRID byte is TRUE (1), it's EWKB |
243 | - if ($bytes[5]) return 'ewkb'; |
|
244 | - else return 'wkb'; |
|
249 | + if ($bytes[5]) { |
|
250 | + return 'ewkb'; |
|
251 | + } else { |
|
252 | + return 'wkb'; |
|
253 | + } |
|
245 | 254 | } |
246 | 255 | |
247 | 256 | // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1) |
@@ -274,12 +283,24 @@ discard block |
||
274 | 283 | if ($bytes[1] == 60) { |
275 | 284 | // grab the first 256 characters |
276 | 285 | $string = substr($input, 0, 256); |
277 | - if (strpos($string, '<kml') !== FALSE) return 'kml'; |
|
278 | - if (strpos($string, '<coordinate') !== FALSE) return 'kml'; |
|
279 | - if (strpos($string, '<gpx') !== FALSE) return 'gpx'; |
|
280 | - if (strpos($string, '<georss') !== FALSE) return 'georss'; |
|
281 | - if (strpos($string, '<rss') !== FALSE) return 'georss'; |
|
282 | - if (strpos($string, '<feed') !== FALSE) return 'georss'; |
|
286 | + if (strpos($string, '<kml') !== FALSE) { |
|
287 | + return 'kml'; |
|
288 | + } |
|
289 | + if (strpos($string, '<coordinate') !== FALSE) { |
|
290 | + return 'kml'; |
|
291 | + } |
|
292 | + if (strpos($string, '<gpx') !== FALSE) { |
|
293 | + return 'gpx'; |
|
294 | + } |
|
295 | + if (strpos($string, '<georss') !== FALSE) { |
|
296 | + return 'georss'; |
|
297 | + } |
|
298 | + if (strpos($string, '<rss') !== FALSE) { |
|
299 | + return 'georss'; |
|
300 | + } |
|
301 | + if (strpos($string, '<feed') !== FALSE) { |
|
302 | + return 'georss'; |
|
303 | + } |
|
283 | 304 | } |
284 | 305 | |
285 | 306 | // We need an 8 byte string for geohash and unpacked WKB / WKT |