@@ -290,7 +290,9 @@ |
||
290 | 290 | |
291 | 291 | function _methods_tester_with_geos($geometry) { |
292 | 292 | // Cannot test methods if GEOS is not intstalled |
293 | - if (!geoPHP::geosInstalled()) return; |
|
293 | + if (!geoPHP::geosInstalled()) { |
|
294 | + return; |
|
295 | + } |
|
294 | 296 | |
295 | 297 | $methods = array( |
296 | 298 | //'boundary', //@@TODO: Uncomment this and fix errors |
@@ -32,7 +32,9 @@ |
||
32 | 32 | |
33 | 33 | // Test to make sure adapter work the same wether GEOS is ON or OFF |
34 | 34 | // Cannot test methods if GEOS is not intstalled |
35 | - if (!geoPHP::geosInstalled()) return; |
|
35 | + if (!geoPHP::geosInstalled()) { |
|
36 | + return; |
|
37 | + } |
|
36 | 38 | |
37 | 39 | foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) { |
38 | 40 | if ($adapter_key != 'google_geocode') { //Don't test google geocoder regularily. Uncomment to test |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | if (geoPHP::geosInstalled()) { |
14 | 14 | print "GEOS is installed.\n"; |
15 | - } |
|
16 | - else { |
|
15 | + } else { |
|
17 | 16 | print "GEOS is not installed.\n"; |
18 | 17 | } |
19 | 18 | |
@@ -125,8 +124,7 @@ discard block |
||
125 | 124 | if ($test_geom_1->out('wkt') != $test_geom_2->out('wkt')) { |
126 | 125 | print "Mismatched adapter output in ".$adapter_class."\n"; |
127 | 126 | } |
128 | - } |
|
129 | - else { |
|
127 | + } else { |
|
130 | 128 | print "Empty output on " . $adapter_key . "\n"; |
131 | 129 | } |
132 | 130 | } |
@@ -134,7 +132,9 @@ discard block |
||
134 | 132 | |
135 | 133 | // Test to make sure adapter work the same wether GEOS is ON or OFF |
136 | 134 | // Cannot test methods if GEOS is not intstalled |
137 | - if (!geoPHP::geosInstalled()) return; |
|
135 | + if (!geoPHP::geosInstalled()) { |
|
136 | + return; |
|
137 | + } |
|
138 | 138 | |
139 | 139 | foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) { |
140 | 140 | if ($adapter_key != 'google_geocode') { //Don't test google geocoder regularily. Uncomment to test |
@@ -167,7 +167,9 @@ discard block |
||
167 | 167 | |
168 | 168 | function test_methods($geometry) { |
169 | 169 | // Cannot test methods if GEOS is not intstalled |
170 | - if (!geoPHP::geosInstalled()) return; |
|
170 | + if (!geoPHP::geosInstalled()) { |
|
171 | + return; |
|
172 | + } |
|
171 | 173 | |
172 | 174 | $methods = array( |
173 | 175 | //'boundary', //@@TODO: Uncomment this and fix errors |
@@ -237,8 +239,11 @@ discard block |
||
237 | 239 | function test_detection($value, $format, $file) { |
238 | 240 | $detected = geoPHP::detectFormat($value); |
239 | 241 | if ($detected != $format) { |
240 | - if ($detected) print 'detected as ' . $detected . "\n"; |
|
241 | - else print "not detected\n"; |
|
242 | + if ($detected) { |
|
243 | + print 'detected as ' . $detected . "\n"; |
|
244 | + } else { |
|
245 | + print "not detected\n"; |
|
246 | + } |
|
242 | 247 | } |
243 | 248 | // Make sure it loads using auto-detect |
244 | 249 | geoPHP::load($value); |
@@ -19,8 +19,7 @@ |
||
19 | 19 | $wkt = 'SRID=' . $srid . ';'; |
20 | 20 | $wkt .= $geometry->out('wkt'); |
21 | 21 | return $wkt; |
22 | - } |
|
23 | - else { |
|
22 | + } else { |
|
24 | 23 | return $geometry->out('wkt'); |
25 | 24 | } |
26 | 25 | } |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | if (!($key % 2)) { |
88 | 88 | // It's a latitude |
89 | 89 | $lat = $item; |
90 | - } |
|
91 | - else { |
|
90 | + } else { |
|
92 | 91 | // It's a longitude |
93 | 92 | $lon = $item; |
94 | 93 | $coords[] = new Point($lon, $lat); |
@@ -125,8 +124,7 @@ discard block |
||
125 | 124 | $points = $this->getPointsFromCoords(trim($poly->firstChild->nodeValue)); |
126 | 125 | $exterior_ring = new LineString($points); |
127 | 126 | $polygons[] = new Polygon(array($exterior_ring)); |
128 | - } |
|
129 | - else { |
|
127 | + } else { |
|
130 | 128 | // It's an EMPTY polygon |
131 | 129 | $polygons[] = new Polygon(); |
132 | 130 | } |
@@ -196,7 +194,9 @@ discard block |
||
196 | 194 | $output = '<'.$this->nss.'line>'; |
197 | 195 | foreach ($geom->getComponents() as $k => $point) { |
198 | 196 | $output .= $point->getY().' '.$point->getX(); |
199 | - if ($k < ($geom->numGeometries() -1)) $output .= ' '; |
|
197 | + if ($k < ($geom->numGeometries() -1)) { |
|
198 | + $output .= ' '; |
|
199 | + } |
|
200 | 200 | } |
201 | 201 | $output .= '</'.$this->nss.'line>'; |
202 | 202 | return $output; |
@@ -207,7 +207,9 @@ discard block |
||
207 | 207 | $exterior_ring = $geom->exteriorRing(); |
208 | 208 | foreach ($exterior_ring->getComponents() as $k => $point) { |
209 | 209 | $output .= $point->getY().' '.$point->getX(); |
210 | - if ($k < ($exterior_ring->numGeometries() -1)) $output .= ' '; |
|
210 | + if ($k < ($exterior_ring->numGeometries() -1)) { |
|
211 | + $output .= ' '; |
|
212 | + } |
|
211 | 213 | } |
212 | 214 | $output .= '</'.$this->nss.'polygon>'; |
213 | 215 | return $output; |
@@ -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 | |
@@ -71,7 +68,9 @@ discard block |
||
71 | 68 | $data_string = $this->trimParens($data_string); |
72 | 69 | |
73 | 70 | // If it's marked as empty, then return an empty line |
74 | - if ($data_string == 'EMPTY') return new LineString(); |
|
71 | + if ($data_string == 'EMPTY') { |
|
72 | + return new LineString(); |
|
73 | + } |
|
75 | 74 | |
76 | 75 | $parts = explode(',',$data_string); |
77 | 76 | $points = array(); |
@@ -85,13 +84,19 @@ discard block |
||
85 | 84 | $data_string = $this->trimParens($data_string); |
86 | 85 | |
87 | 86 | // If it's marked as empty, then return an empty polygon |
88 | - if ($data_string == 'EMPTY') return new Polygon(); |
|
87 | + if ($data_string == 'EMPTY') { |
|
88 | + return new Polygon(); |
|
89 | + } |
|
89 | 90 | |
90 | 91 | $parts = explode('),(',$data_string); |
91 | 92 | $lines = array(); |
92 | 93 | foreach ($parts as $part) { |
93 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
94 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
94 | + if (!$this->beginsWith($part,'(')) { |
|
95 | + $part = '(' . $part; |
|
96 | + } |
|
97 | + if (!$this->endsWith($part,')')) { |
|
98 | + $part = $part . ')'; |
|
99 | + } |
|
95 | 100 | $lines[] = $this->parseLineString($part); |
96 | 101 | } |
97 | 102 | return new Polygon($lines); |
@@ -101,7 +106,9 @@ discard block |
||
101 | 106 | $data_string = $this->trimParens($data_string); |
102 | 107 | |
103 | 108 | // If it's marked as empty, then return an empty MutiPoint |
104 | - if ($data_string == 'EMPTY') return new MultiPoint(); |
|
109 | + if ($data_string == 'EMPTY') { |
|
110 | + return new MultiPoint(); |
|
111 | + } |
|
105 | 112 | |
106 | 113 | $parts = explode(',',$data_string); |
107 | 114 | $points = array(); |
@@ -115,14 +122,20 @@ discard block |
||
115 | 122 | $data_string = $this->trimParens($data_string); |
116 | 123 | |
117 | 124 | // If it's marked as empty, then return an empty multi-linestring |
118 | - if ($data_string == 'EMPTY') return new MultiLineString(); |
|
125 | + if ($data_string == 'EMPTY') { |
|
126 | + return new MultiLineString(); |
|
127 | + } |
|
119 | 128 | |
120 | 129 | $parts = explode('),(',$data_string); |
121 | 130 | $lines = array(); |
122 | 131 | foreach ($parts as $part) { |
123 | 132 | // Repair the string if the explode broke it |
124 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
125 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
133 | + if (!$this->beginsWith($part,'(')) { |
|
134 | + $part = '(' . $part; |
|
135 | + } |
|
136 | + if (!$this->endsWith($part,')')) { |
|
137 | + $part = $part . ')'; |
|
138 | + } |
|
126 | 139 | $lines[] = $this->parseLineString($part); |
127 | 140 | } |
128 | 141 | return new MultiLineString($lines); |
@@ -132,14 +145,20 @@ discard block |
||
132 | 145 | $data_string = $this->trimParens($data_string); |
133 | 146 | |
134 | 147 | // If it's marked as empty, then return an empty multi-polygon |
135 | - if ($data_string == 'EMPTY') return new MultiPolygon(); |
|
148 | + if ($data_string == 'EMPTY') { |
|
149 | + return new MultiPolygon(); |
|
150 | + } |
|
136 | 151 | |
137 | 152 | $parts = explode(')),((',$data_string); |
138 | 153 | $polys = array(); |
139 | 154 | foreach ($parts as $part) { |
140 | 155 | // Repair the string if the explode broke it |
141 | - if (!$this->beginsWith($part,'((')) $part = '((' . $part; |
|
142 | - if (!$this->endsWith($part,'))')) $part = $part . '))'; |
|
156 | + if (!$this->beginsWith($part,'((')) { |
|
157 | + $part = '((' . $part; |
|
158 | + } |
|
159 | + if (!$this->endsWith($part,'))')) { |
|
160 | + $part = $part . '))'; |
|
161 | + } |
|
143 | 162 | $polys[] = $this->parsePolygon($part); |
144 | 163 | } |
145 | 164 | return new MultiPolygon($polys); |
@@ -149,7 +168,9 @@ discard block |
||
149 | 168 | $data_string = $this->trimParens($data_string); |
150 | 169 | |
151 | 170 | // If it's marked as empty, then return an empty geom-collection |
152 | - if ($data_string == 'EMPTY') return new GeometryCollection(); |
|
171 | + if ($data_string == 'EMPTY') { |
|
172 | + return new GeometryCollection(); |
|
173 | + } |
|
153 | 174 | |
154 | 175 | $geometries = array(); |
155 | 176 | $matches = array(); |
@@ -180,18 +201,25 @@ discard block |
||
180 | 201 | // We want to only strip off one set of parenthesis |
181 | 202 | if ($this->beginsWith($str, '(')) { |
182 | 203 | return substr($str,1,-1); |
204 | + } else { |
|
205 | + return $str; |
|
183 | 206 | } |
184 | - else return $str; |
|
185 | 207 | } |
186 | 208 | |
187 | 209 | protected function beginsWith($str, $char) { |
188 | - if (substr($str,0,strlen($char)) == $char) return TRUE; |
|
189 | - else return FALSE; |
|
210 | + if (substr($str,0,strlen($char)) == $char) { |
|
211 | + return TRUE; |
|
212 | + } else { |
|
213 | + return FALSE; |
|
214 | + } |
|
190 | 215 | } |
191 | 216 | |
192 | 217 | protected function endsWith($str, $char) { |
193 | - if (substr($str,(0 - strlen($char))) == $char) return TRUE; |
|
194 | - else return FALSE; |
|
218 | + if (substr($str,(0 - strlen($char))) == $char) { |
|
219 | + return TRUE; |
|
220 | + } else { |
|
221 | + return FALSE; |
|
222 | + } |
|
195 | 223 | } |
196 | 224 | |
197 | 225 | /** |
@@ -211,8 +239,7 @@ discard block |
||
211 | 239 | |
212 | 240 | if ($geometry->isEmpty()) { |
213 | 241 | return strtoupper($geometry->geometryType()).' EMPTY'; |
214 | - } |
|
215 | - else if ($data = $this->extractData($geometry)) { |
|
242 | + } else if ($data = $this->extractData($geometry)) { |
|
216 | 243 | return strtoupper($geometry->geometryType()).' ('.$data.')'; |
217 | 244 | } |
218 | 245 | } |
@@ -30,15 +30,16 @@ discard block |
||
30 | 30 | * @return Geometry|GeometryCollection |
31 | 31 | */ |
32 | 32 | public function read($address, $return_type = 'point', $bounds = FALSE, $return_multiple = FALSE) { |
33 | - if (is_array($address)) $address = join(',', $address); |
|
33 | + if (is_array($address)) { |
|
34 | + $address = join(',', $address); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | if (gettype($bounds) == 'object') { |
36 | 38 | $bounds = $bounds->getBBox(); |
37 | 39 | } |
38 | 40 | if (gettype($bounds) == 'array') { |
39 | 41 | $bounds_string = '&bounds='.$bounds['miny'].','.$bounds['minx'].'|'.$bounds['maxy'].','.$bounds['maxx']; |
40 | - } |
|
41 | - else { |
|
42 | + } else { |
|
42 | 43 | $bounds_string = ''; |
43 | 44 | } |
44 | 45 | |
@@ -73,10 +74,12 @@ discard block |
||
73 | 74 | return new MultiPolygon($polygons); |
74 | 75 | } |
75 | 76 | } |
76 | - } |
|
77 | - else { |
|
78 | - if ($this->result->status) throw new Exception('Error in Google Geocoder: '.$this->result->status); |
|
79 | - else throw new Exception('Unknown error in Google Geocoder'); |
|
77 | + } else { |
|
78 | + if ($this->result->status) { |
|
79 | + throw new Exception('Error in Google Geocoder: '.$this->result->status); |
|
80 | + } else { |
|
81 | + throw new Exception('Unknown error in Google Geocoder'); |
|
82 | + } |
|
80 | 83 | return FALSE; |
81 | 84 | } |
82 | 85 | } |
@@ -106,10 +109,12 @@ discard block |
||
106 | 109 | if ($return_type == 'array') { |
107 | 110 | return $this->result->results[0]->address_components; |
108 | 111 | } |
109 | - } |
|
110 | - else { |
|
111 | - if ($this->result->status) throw new Exception('Error in Google Reverse Geocoder: '.$this->result->status); |
|
112 | - else throw new Exception('Unknown error in Google Reverse Geocoder'); |
|
112 | + } else { |
|
113 | + if ($this->result->status) { |
|
114 | + throw new Exception('Error in Google Reverse Geocoder: '.$this->result->status); |
|
115 | + } else { |
|
116 | + throw new Exception('Unknown error in Google Reverse Geocoder'); |
|
117 | + } |
|
113 | 118 | return FALSE; |
114 | 119 | } |
115 | 120 | } |
@@ -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 | } |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | $ll = $this->decode($hash); |
20 | 20 | if (!$as_grid) { |
21 | 21 | return new Point($ll['medlon'], $ll['medlat']); |
22 | - } |
|
23 | - else { |
|
22 | + } else { |
|
24 | 23 | return new Polygon(array( |
25 | 24 | new LineString(array( |
26 | 25 | new Point($ll['minlon'], $ll['maxlat']), |
@@ -40,12 +39,13 @@ discard block |
||
40 | 39 | * @see GeoAdapter::write() |
41 | 40 | */ |
42 | 41 | public function write(Geometry $geometry, $precision = NULL){ |
43 | - if ($geometry->isEmpty()) return ''; |
|
42 | + if ($geometry->isEmpty()) { |
|
43 | + return ''; |
|
44 | + } |
|
44 | 45 | |
45 | 46 | if($geometry->geometryType() === 'Point'){ |
46 | 47 | return $this->encodePoint($geometry, $precision); |
47 | - } |
|
48 | - else { |
|
48 | + } else { |
|
49 | 49 | // The geohash is the hash grid ID that fits the envelope |
50 | 50 | $envelope = $geometry->envelope(); |
51 | 51 | $geohashes = array(); |
@@ -138,19 +138,59 @@ discard block |
||
138 | 138 | for($i=0,$c=strlen($hash);$i<$c;$i++) { |
139 | 139 | $v = strpos($this->table,$hash[$i]); |
140 | 140 | if(1&$i) { |
141 | - if(16&$v)$minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
142 | - if(8&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
143 | - if(4&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
144 | - if(2&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
145 | - if(1&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
141 | + if(16&$v) { |
|
142 | + $minlat = ($minlat+$maxlat)/2; |
|
143 | + } else { |
|
144 | + $maxlat = ($minlat+$maxlat)/2; |
|
145 | + } |
|
146 | + if(8&$v) { |
|
147 | + $minlon = ($minlon+$maxlon)/2; |
|
148 | + } else { |
|
149 | + $maxlon = ($minlon+$maxlon)/2; |
|
150 | + } |
|
151 | + if(4&$v) { |
|
152 | + $minlat = ($minlat+$maxlat)/2; |
|
153 | + } else { |
|
154 | + $maxlat = ($minlat+$maxlat)/2; |
|
155 | + } |
|
156 | + if(2&$v) { |
|
157 | + $minlon = ($minlon+$maxlon)/2; |
|
158 | + } else { |
|
159 | + $maxlon = ($minlon+$maxlon)/2; |
|
160 | + } |
|
161 | + if(1&$v) { |
|
162 | + $minlat = ($minlat+$maxlat)/2; |
|
163 | + } else { |
|
164 | + $maxlat = ($minlat+$maxlat)/2; |
|
165 | + } |
|
146 | 166 | $latE /= 8; |
147 | 167 | $lonE /= 4; |
148 | 168 | } else { |
149 | - if(16&$v)$minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
150 | - if(8&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
151 | - if(4&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
152 | - if(2&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
153 | - if(1&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
169 | + if(16&$v) { |
|
170 | + $minlon = ($minlon+$maxlon)/2; |
|
171 | + } else { |
|
172 | + $maxlon = ($minlon+$maxlon)/2; |
|
173 | + } |
|
174 | + if(8&$v) { |
|
175 | + $minlat = ($minlat+$maxlat)/2; |
|
176 | + } else { |
|
177 | + $maxlat = ($minlat+$maxlat)/2; |
|
178 | + } |
|
179 | + if(4&$v) { |
|
180 | + $minlon = ($minlon+$maxlon)/2; |
|
181 | + } else { |
|
182 | + $maxlon = ($minlon+$maxlon)/2; |
|
183 | + } |
|
184 | + if(2&$v) { |
|
185 | + $minlat = ($minlat+$maxlat)/2; |
|
186 | + } else { |
|
187 | + $maxlat = ($minlat+$maxlat)/2; |
|
188 | + } |
|
189 | + if(1&$v) { |
|
190 | + $minlon = ($minlon+$maxlon)/2; |
|
191 | + } else { |
|
192 | + $maxlon = ($minlon+$maxlon)/2; |
|
193 | + } |
|
154 | 194 | $latE /= 4; |
155 | 195 | $lonE /= 8; |
156 | 196 | } |