@@ -120,8 +120,7 @@ discard block |
||
120 | 120 | public function write(Geometry $geometry, $return_array = FALSE) { |
121 | 121 | if ($return_array) { |
122 | 122 | return $this->getArray($geometry); |
123 | - } |
|
124 | - else { |
|
123 | + } else { |
|
125 | 124 | return json_encode($this->getArray($geometry)); |
126 | 125 | } |
127 | 126 | } |
@@ -139,11 +138,12 @@ discard block |
||
139 | 138 | 'type'=> 'GeometryCollection', |
140 | 139 | 'geometries'=> $component_array, |
141 | 140 | ); |
142 | - } |
|
143 | - else return array( |
|
141 | + } else { |
|
142 | + return array( |
|
144 | 143 | 'type'=> $geometry->getGeomType(), |
145 | 144 | 'coordinates'=> $geometry->asArray(), |
146 | 145 | ); |
146 | + } |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 |
@@ -94,7 +94,9 @@ discard block |
||
94 | 94 | $line_length = unpack('L',fread($mem,4)); |
95 | 95 | |
96 | 96 | // Return an empty linestring if there is no line-length |
97 | - if (!$line_length[1]) return new LineString(); |
|
97 | + if (!$line_length[1]) { |
|
98 | + return new LineString(); |
|
99 | + } |
|
98 | 100 | |
99 | 101 | // Read the nubmer of points x2 (each point is two coords) into decimal-floats |
100 | 102 | $line_coords = unpack('d*', fread($mem,$line_length[1]*$this->dimension*8)); |
@@ -190,8 +192,7 @@ discard block |
||
190 | 192 | if ($write_as_hex) { |
191 | 193 | $unpacked = unpack('H*',$wkb); |
192 | 194 | return $unpacked[1]; |
193 | - } |
|
194 | - else { |
|
195 | + } else { |
|
195 | 196 | return $wkb; |
196 | 197 | } |
197 | 198 | } |
@@ -89,8 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | - } |
|
93 | - else { |
|
92 | + } else { |
|
94 | 93 | // The document does not have a placemark, try to create a valid geometry from the root element |
95 | 94 | $node_name = $this->xmlobj->documentElement->nodeName == 'multigeometry' ? 'geometrycollection' : $this->xmlobj->documentElement->nodeName; |
96 | 95 | if (array_key_exists($node_name, $geom_types)) { |
@@ -220,7 +219,9 @@ discard block |
||
220 | 219 | $str .= '<'.$this->nss.'coordinates>'; |
221 | 220 | $i=0; |
222 | 221 | foreach ($geom->getComponents() as $comp) { |
223 | - if ($i != 0) $str .= ' '; |
|
222 | + if ($i != 0) { |
|
223 | + $str .= ' '; |
|
224 | + } |
|
224 | 225 | $str .= $comp->getX() .','. $comp->getY(); |
225 | 226 | $i++; |
226 | 227 | } |
@@ -9,7 +9,9 @@ discard block |
||
9 | 9 | protected $geom_type = 'Polygon'; |
10 | 10 | |
11 | 11 | public function area($exterior_only = FALSE, $signed = FALSE) { |
12 | - if ($this->isEmpty()) return 0; |
|
12 | + if ($this->isEmpty()) { |
|
13 | + return 0; |
|
14 | + } |
|
13 | 15 | |
14 | 16 | if ($this->geos() && $exterior_only == FALSE) { |
15 | 17 | return $this->geos()->area(); |
@@ -19,15 +21,20 @@ discard block |
||
19 | 21 | $pts = $exterior_ring->getComponents(); |
20 | 22 | |
21 | 23 | $c = count($pts); |
22 | - if((int)$c == '0') return NULL; |
|
24 | + if((int)$c == '0') { |
|
25 | + return NULL; |
|
26 | + } |
|
23 | 27 | $a = '0'; |
24 | 28 | foreach($pts as $k => $p){ |
25 | 29 | $j = ($k + 1) % $c; |
26 | 30 | $a = $a + ($p->getX() * $pts[$j]->getY()) - ($p->getY() * $pts[$j]->getX()); |
27 | 31 | } |
28 | 32 | |
29 | - if ($signed) $area = ($a / 2); |
|
30 | - else $area = abs(($a / 2)); |
|
33 | + if ($signed) { |
|
34 | + $area = ($a / 2); |
|
35 | + } else { |
|
36 | + $area = abs(($a / 2)); |
|
37 | + } |
|
31 | 38 | |
32 | 39 | if ($exterior_only == TRUE) { |
33 | 40 | return $area; |
@@ -42,7 +49,9 @@ discard block |
||
42 | 49 | } |
43 | 50 | |
44 | 51 | public function centroid() { |
45 | - if ($this->isEmpty()) return NULL; |
|
52 | + if ($this->isEmpty()) { |
|
53 | + return NULL; |
|
54 | + } |
|
46 | 55 | |
47 | 56 | if ($this->geos()) { |
48 | 57 | return geoPHP::geosToGeometry($this->geos()->centroid()); |
@@ -52,7 +61,9 @@ discard block |
||
52 | 61 | $pts = $exterior_ring->getComponents(); |
53 | 62 | |
54 | 63 | $c = count($pts); |
55 | - if((int)$c == '0') return NULL; |
|
64 | + if((int)$c == '0') { |
|
65 | + return NULL; |
|
66 | + } |
|
56 | 67 | $cn = array('x' => '0', 'y' => '0'); |
57 | 68 | $a = $this->area(TRUE, TRUE); |
58 | 69 | |
@@ -98,12 +109,16 @@ discard block |
||
98 | 109 | } |
99 | 110 | |
100 | 111 | public function exteriorRing() { |
101 | - if ($this->isEmpty()) return new LineString(); |
|
112 | + if ($this->isEmpty()) { |
|
113 | + return new LineString(); |
|
114 | + } |
|
102 | 115 | return $this->components[0]; |
103 | 116 | } |
104 | 117 | |
105 | 118 | public function numInteriorRings() { |
106 | - if ($this->isEmpty()) return 0; |
|
119 | + if ($this->isEmpty()) { |
|
120 | + return 0; |
|
121 | + } |
|
107 | 122 | return $this->numGeometries()-1; |
108 | 123 | } |
109 | 124 | |
@@ -112,7 +127,9 @@ discard block |
||
112 | 127 | } |
113 | 128 | |
114 | 129 | public function dimension() { |
115 | - if ($this->isEmpty()) return 0; |
|
130 | + if ($this->isEmpty()) { |
|
131 | + return 0; |
|
132 | + } |
|
116 | 133 | return 2; |
117 | 134 | } |
118 | 135 | |
@@ -187,8 +204,7 @@ discard block |
||
187 | 204 | // If the number of edges we passed through is even, then it's in the polygon. |
188 | 205 | if ($intersections % 2 != 0) { |
189 | 206 | return TRUE; |
190 | - } |
|
191 | - else { |
|
207 | + } else { |
|
192 | 208 | return FALSE; |
193 | 209 | } |
194 | 210 | } |
@@ -71,8 +71,9 @@ |
||
71 | 71 | public function z() { |
72 | 72 | if ($this->dimention == 3) { |
73 | 73 | return $this->coords[2]; |
74 | + } else { |
|
75 | + return NULL; |
|
74 | 76 | } |
75 | - else return NULL; |
|
76 | 77 | } |
77 | 78 | |
78 | 79 | // A point's centroid is itself |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | foreach ($components as $component) { |
25 | 25 | if ($component instanceof Geometry) { |
26 | 26 | $this->components[] = $component; |
27 | - } |
|
28 | - else { |
|
27 | + } else { |
|
29 | 28 | throw new Exception("Cannot create a collection with non-geometries"); |
30 | 29 | } |
31 | 30 | } |
@@ -41,7 +40,9 @@ discard block |
||
41 | 40 | } |
42 | 41 | |
43 | 42 | public function centroid() { |
44 | - if ($this->isEmpty()) return NULL; |
|
43 | + if ($this->isEmpty()) { |
|
44 | + return NULL; |
|
45 | + } |
|
45 | 46 | |
46 | 47 | if ($this->geos()) { |
47 | 48 | $geos_centroid = $this->geos()->centroid(); |
@@ -59,7 +60,9 @@ discard block |
||
59 | 60 | } |
60 | 61 | |
61 | 62 | public function getBBox() { |
62 | - if ($this->isEmpty()) return NULL; |
|
63 | + if ($this->isEmpty()) { |
|
64 | + return NULL; |
|
65 | + } |
|
63 | 66 | |
64 | 67 | if ($this->geos()) { |
65 | 68 | $envelope = $this->geos()->envelope(); |
@@ -127,7 +130,9 @@ discard block |
||
127 | 130 | |
128 | 131 | // By default, the boundary of a collection is the boundary of it's components |
129 | 132 | public function boundary() { |
130 | - if ($this->isEmpty()) return new LineString(); |
|
133 | + if ($this->isEmpty()) { |
|
134 | + return new LineString(); |
|
135 | + } |
|
131 | 136 | |
132 | 137 | if ($this->geos()) { |
133 | 138 | return $this->geos()->boundary(); |
@@ -149,8 +154,7 @@ discard block |
||
149 | 154 | $n = intval($n); |
150 | 155 | if (array_key_exists($n-1, $this->components)) { |
151 | 156 | return $this->components[$n-1]; |
152 | - } |
|
153 | - else { |
|
157 | + } else { |
|
154 | 158 | return NULL; |
155 | 159 | } |
156 | 160 | } |
@@ -193,10 +197,11 @@ discard block |
||
193 | 197 | public function isEmpty() { |
194 | 198 | if (!count($this->components)) { |
195 | 199 | return TRUE; |
196 | - } |
|
197 | - else { |
|
200 | + } else { |
|
198 | 201 | foreach ($this->components as $component) { |
199 | - if (!$component->isEmpty()) return FALSE; |
|
202 | + if (!$component->isEmpty()) { |
|
203 | + return FALSE; |
|
204 | + } |
|
200 | 205 | } |
201 | 206 | return TRUE; |
202 | 207 | } |
@@ -263,7 +268,9 @@ discard block |
||
263 | 268 | |
264 | 269 | // A collection is simple if all it's components are simple |
265 | 270 | foreach ($this->components as $component) { |
266 | - if (!$component->isSimple()) return FALSE; |
|
271 | + if (!$component->isSimple()) { |
|
272 | + return FALSE; |
|
273 | + } |
|
267 | 274 | } |
268 | 275 | |
269 | 276 | return TRUE; |
@@ -54,7 +54,9 @@ |
||
54 | 54 | } |
55 | 55 | |
56 | 56 | public function dimension() { |
57 | - if ($this->isEmpty()) return 0; |
|
57 | + if ($this->isEmpty()) { |
|
58 | + return 0; |
|
59 | + } |
|
58 | 60 | return 1; |
59 | 61 | } |
60 | 62 |
@@ -57,7 +57,9 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | public function envelope() { |
60 | - if ($this->isEmpty()) return new Polygon(); |
|
60 | + if ($this->isEmpty()) { |
|
61 | + return new Polygon(); |
|
62 | + } |
|
61 | 63 | |
62 | 64 | if ($this->geos()) { |
63 | 65 | return geoPHP::geosToGeometry($this->geos()->envelope()); |
@@ -148,8 +150,7 @@ discard block |
||
148 | 150 | if (geoPHP::geosInstalled()) { |
149 | 151 | $reader = new GEOSWKBReader(); |
150 | 152 | $this->geos = $reader->readHEX($this->out('wkb',TRUE)); |
151 | - } |
|
152 | - else { |
|
153 | + } else { |
|
153 | 154 | $this->geos = FALSE; |
154 | 155 | } |
155 | 156 | return $this->geos; |
@@ -175,8 +176,7 @@ discard block |
||
175 | 176 | if ($this->geos()) { |
176 | 177 | if ($pattern) { |
177 | 178 | return $this->geos()->relate($geometry->geos(), $pattern); |
178 | - } |
|
179 | - else { |
|
179 | + } else { |
|
180 | 180 | return $this->geos()->relate($geometry->geos()); |
181 | 181 | } |
182 | 182 | } |
@@ -227,8 +227,7 @@ discard block |
||
227 | 227 | $geom = $geom->union($item->geos()); |
228 | 228 | } |
229 | 229 | return geoPHP::geosToGeometry($geom); |
230 | - } |
|
231 | - else { |
|
230 | + } else { |
|
232 | 231 | return geoPHP::geosToGeometry($this->geos()->union($geometry->geos())); |
233 | 232 | } |
234 | 233 | } |
@@ -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); |
@@ -120,7 +122,9 @@ discard block |
||
120 | 122 | |
121 | 123 | static function geosInstalled($force = NULL) { |
122 | 124 | static $geos_installed = NULL; |
123 | - if ($force !== NULL) $geos_installed = $force; |
|
125 | + if ($force !== NULL) { |
|
126 | + $geos_installed = $force; |
|
127 | + } |
|
124 | 128 | if ($geos_installed !== NULL) { |
125 | 129 | return $geos_installed; |
126 | 130 | } |
@@ -148,8 +152,12 @@ discard block |
||
148 | 152 | static function geometryReduce($geometry) { |
149 | 153 | // If it's an array of one, then just parse the one |
150 | 154 | if (is_array($geometry)) { |
151 | - if (empty($geometry)) return FALSE; |
|
152 | - if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
155 | + if (empty($geometry)) { |
|
156 | + return FALSE; |
|
157 | + } |
|
158 | + if (count($geometry) == 1) { |
|
159 | + return geoPHP::geometryReduce(array_shift($geometry)); |
|
160 | + } |
|
153 | 161 | } |
154 | 162 | |
155 | 163 | // If the geometry cannot even theoretically be reduced more, then pass it back |
@@ -168,8 +176,7 @@ discard block |
||
168 | 176 | $components = $geometry->getComponents(); |
169 | 177 | if (count($components) == 1) { |
170 | 178 | return $components[0]; |
171 | - } |
|
172 | - else { |
|
179 | + } else { |
|
173 | 180 | return $geometry; |
174 | 181 | } |
175 | 182 | } |
@@ -192,8 +199,7 @@ discard block |
||
192 | 199 | $geometries[] = $component; |
193 | 200 | $geom_types[] = $component->geometryType(); |
194 | 201 | } |
195 | - } |
|
196 | - else { |
|
202 | + } else { |
|
197 | 203 | $geometries[] = $item; |
198 | 204 | $geom_types[] = $item->geometryType(); |
199 | 205 | } |
@@ -209,13 +215,11 @@ discard block |
||
209 | 215 | if (count($geom_types) == 1) { |
210 | 216 | if (count($geometries) == 1) { |
211 | 217 | return $geometries[0]; |
212 | - } |
|
213 | - else { |
|
218 | + } else { |
|
214 | 219 | $class = 'Multi'.$geom_types[0]; |
215 | 220 | return new $class($geometries); |
216 | 221 | } |
217 | - } |
|
218 | - else { |
|
222 | + } else { |
|
219 | 223 | return new GeometryCollection($geometries); |
220 | 224 | } |
221 | 225 | } |
@@ -230,7 +234,9 @@ discard block |
||
230 | 234 | $bytes = unpack("c*", fread($mem, 11)); |
231 | 235 | |
232 | 236 | // If bytes is empty, then we were passed empty input |
233 | - if (empty($bytes)) return FALSE; |
|
237 | + if (empty($bytes)) { |
|
238 | + return FALSE; |
|
239 | + } |
|
234 | 240 | |
235 | 241 | // First char is a tab, space or carriage-return. trim it and try again |
236 | 242 | 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 |